Hi. I have this script in a tool to make it "Click to pickup"
local destroyMe = script.Parent:WaitForChild("Handle"):FindFirstChild("TouchInterest") local tool = script.Parent if destroyMe then destroyMe:Destroy() end script.Parent.ClickDetector.MouseClick:Connect(function(plr) tool.Parent = plr.Backpack end)
And it works! But when i drop tool from Backpack ("tool.Parent = game.Workspace") ClickDetector not detecting any clicks anymore. Am i doing something wrong?
Thanks guys ;)
SOLUTION Before adding tool to backpack, make it parent nil!
script.Parent.ClickDetector.MouseClick:Connect(function(plr) tool.Parent = nil tool.Parent = plr.Backpack
What you want to do is clone the tool:
local Handle = script.Parent:WaitForChild("Handle") local Destroyme = Handle:FindFirstChild("TouchInterest") local ClickDetect = script.Parent:WaitForChild("ClickDetector") local Tool = script.Parent if Destroyme then Destroyme:Destroy() end ClickDetect.MouseClick:Connect(function(plr) local Clone = Tool:Clone() Clone.Parent = plr.Backpack end
This clones the tool into the players backpack. Its advised you add some security mesures so they cant pick up multiple items which would be to check if they have it with if plr.Backpack:FindFirstChild(Tool.Name) then return end