|
i have a script to make a part follow the mouse when a tool is equipped
player = game.Players.LocalPlayer
mouse = player:GetMouse()
clicky = game.Workspace.placey
tool = script.Parent
local function onEquip()
brick = Instance.new("Part",workspace)
brick.BrickColor = BrickColor.new(1020)
brick.Size = Vector3.new( .01, 4, 4)
brick.Shape = "Cylinder"
brick.Anchored = true
mouse.TargetFilter = brick
mouse.Move:connect(function()
if mouse.Hit then
brick.CFrame = mouse.Hit
brick.Rotation = Vector3.new(0,0,-90)
end
end)
end
tool.Equipped:connect(onEquip)
if i take off the onEquip part, it works fine, but it never goes away. i want it to go away when i unequip the tool. any idea whats up with this? |
|
Hedr0nJoin Date: 2016-01-05 Post Count: 1524 |
i have a script to make a part follow the mouse when a tool is equipped
player = game.Players.LocalPlayer
mouse = player:GetMouse()
clicky = game.Workspace.placey
tool = script.Parent
local event
local function onEquip()
brick = Instance.new("Part",workspace)
brick.BrickColor = BrickColor.new(1020)
brick.Size = Vector3.new( .01, 4, 4)
brick.Shape = "Cylinder"
brick.Anchored = true
mouse.TargetFilter = brick
event = mouse.Move:connect(function()
if mouse.Hit then
brick.CFrame = mouse.Hit
brick.Rotation = Vector3.new(0,0,-90)
end
end)
end
tool.Equipped:connect(onEquip)
tool.Uneqipped:connect(function()
event:Disconnect()
event = nil
end
Gotta clean up your events boyo |
|
|
didnt work, nothing was in the output |
|
Hedr0nJoin Date: 2016-01-05 Post Count: 1524 |
Make sure unequivocal is a actual event. |
|
|
|
Hmm... Wiki kinda sucks when it comes to mouse documentation. However, I got the following to work by putting a Tool in the StarterPack, inserted a Part under Tool, made it invisible, called it Handle, put a LocalScript under the Tool, inserted the following code:
player = game.Players.LocalPlayer
mouse = player:GetMouse()
--clicky = game.Workspace.placey
tool = script.Parent
local function onEquip()
brick = Instance.new("Part",workspace)
brick.BrickColor = BrickColor.new(1020)
brick.Size = Vector3.new( .01, 4, 4)
brick.Shape = "Cylinder"
brick.Anchored = true
mouse.TargetFilter = brick
mouse.Move:connect(function()
if mouse then
brick.CFrame = CFrame.new(mouse.Hit.X, mouse.Hit.Y, mouse.Hit.Z)
brick.Rotation = Vector3.new(0,0,-90)
end
end)
end
tool.Equipped:connect(onEquip)
tool.Unequipped:connect(function()
brick:Destroy()
end) |
|
|
i did what you did, it said in the output
Equipped is not a valid member of Part
14:13:45.629 - Script 'Players.Player.Backpack.Tool.Handle.LocalScript', Line 23
14:13:45.629 - Stack End
i put Script.Parent.Parent for the tool, and it worked. it did send the player to some weird coords, (i think it was 0,0,0) anyway to make the player stay in the current position when they select the tool. it only happens the first time the player selects the tool. but after you die, you get teleported after holding the tool.
|
|
|
Make sure you have your LocalScript under the "Tool". Put a "print(tool.Name) after you set "tool = script.Parent". If it doesn't output "Tool" or whatever you named the Tool then it won't work. The error looks like the LocalScript is under the Handle. |
|
|
|
wait, scratch that. it still teleports me the first time i select the tool. |
|
|
|
|
Not sure why you would teleport...
I did find a bug in the code I gave you:
brick = Instance.new("Part",workspace)
Should be:
brick = Instance.new("Part", game.Workspace)
|
|