Hi. I have this script in a tool to make it "Click to pickup"
01 | local destroyMe = script.Parent:WaitForChild( "Handle" ):FindFirstChild( "TouchInterest" ) |
02 | local tool = script.Parent |
03 |
04 |
05 | if destroyMe then |
06 |
07 | destroyMe:Destroy() |
08 |
09 | end |
10 |
11 | script.Parent.ClickDetector.MouseClick:Connect( function (plr) |
12 |
13 | tool.Parent = plr.Backpack |
14 |
15 | 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!
1 | script.Parent.ClickDetector.MouseClick:Connect( function (plr) |
2 | tool.Parent = nil |
3 | tool.Parent = plr.Backpack |
What you want to do is clone the tool:
01 | local Handle = script.Parent:WaitForChild( "Handle" ) |
02 | local Destroyme = Handle:FindFirstChild( "TouchInterest" ) |
03 | local ClickDetect = script.Parent:WaitForChild( "ClickDetector" ) |
04 | local Tool = script.Parent |
05 |
06 | if Destroyme then |
07 | Destroyme:Destroy() |
08 | end |
09 |
10 | ClickDetect.MouseClick:Connect( function (plr) |
11 | local Clone = Tool:Clone() |
12 | Clone.Parent = plr.Backpack |
13 | 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