Can anyone help me with this code? It only clones the tool and not the scripts and stuff inside the tool.
local button = script.Parent local tool = script.Parent:FindFirstChild("Rifle") local tool2 = script.Parent:FindFirstChild("Shovel") local plr = game.Players.LocalPlayer button.MouseButton1Click:Connect(function() tool:Clone().Parent = plr.Backpack tool2:Clone().Parent = plr.Backpack script.Parent.Parent.Visible = false script.Parent.Parent.Parent.Choose.Visible = false end)
Any help would be appreciated!
From what I can see, it's most likely that the tools aren't there when the script loads in, so the script doesn't know what tool or tool2 is.
To fix this, simply use WaitForChild
. This will wait for the tools to load in before continuing the code.
Example:
local tool = script.Parent:WaitForChild("Rifle") local tool2 = script.Parent:WaitForChild("Shovel")
However, if the tools are not in the correct location where you are referencing it from, there will be an infinite yield. So make sure that the tools have the same parent as the script.
Also, I would not use a local script for this because if the game has FE turned on (which it should), then the tools will not be seen by other players, so I would recommend to use a script for this. You can define the player by using something like local plr = script.Parent.Parent.Parent
, but you'd have to figure out how many .Parent
s you need.