Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

please help with tools?

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?

3 comments

0

Place the part in the player's character model.

0

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

0

sorry M39

2 answers

This will destroy the part when the tool is unequipped. Keep in mind if the player leaves the game or the tool is destroyed in their hand then the brick will not be destroyed.

player = game.Players.LocalPlayer
mouse = player:GetMouse()
clicky = game.Workspace.placey
tool = script.Parent
local brick --define brick variable

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)

tool.Unequipped:connect(function() --fire when the tool is unequipped
if brick then
	brick:Destroy() --if the brick exists then destroy it
end
end)

5 comments

0

oops, i tried putting and onequip function inside of the brick making script. i thought it would only start when i equipped it. thank you

0

oh, it doesnt wrk

0

Any errors? I can't think of any reason why it wouldn't

0

said that it expected a ) to close line 25, i did that, and then nothing in the output, and nothing when i selected the tool.

0

edited

This discussion is preserved as it was. New answers, comments, and votes are closed.