I want to create a tool that is when is clicked it deletes itself and replicates another tool in the user's backpack. No matter what I do it does not work. What am I doing wrong?
Here is my script here: ( local script)
1 | local tool = script.parent; |
1 | x = game.Players.LocalPlayer.Backpack |
2 | z = game.Lighting:WaitForChild( "Cookie" ):clone() |
1 | function onActivated() |
2 | z.Parent = x |
3 | tool: Destroy () |
4 | end |
1 | tool.Activated:connect(onActivated) |
Well, from my experience, you do not have to use:
1 | local tool = script.Parent; |
If it is in a local script
I also think that the ; in this is not suppose to be there
1 | local tool = script.Parent |
if it doesn't work I don't know then.
Try a wait() between z.Parent = x and tool:Destroy() Are you sure z is in lighting? You can try like
1 | repeat |
2 | wait (. 1 ) |
3 | until game.Lighting:FindFirstChild( "Cookie" ) |
Are you sure that z is not nil?