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

Tool Scripts Not Working When Cloned into Player.Backpack?

I am trying to script a tool. When I equip it, it should print out "tool was equipped", and when its activated it should print out "tool was activated". When I have the tool in the starter pack, it works absolutely fine, but when I clone it from the Replicated Storage into Player.Backpack, it doesn't work. I am cloning it through a local script in a shop GUI.

Tool Script:

tool = script.Parent handle = tool:WaitForChild("Handle")

tool.Equipped:Connect(function() print("the tool was equipped") end)

tool.Activated:Connect(function() print("the tool was activated") end)

LocalScript to clone it to Player.Backpack:

local apple = game.ReplicatedStorage:WaitForChild("Apple") local Player = game.Players.LocalPlayer local appleInInv = false

script.Parent.MouseButton1Click:Connect(function() if game.Players.LocalPlayer.leaderstats.Cash.Value >= 1000 and appleInInv == false then local CLONE = apple:Clone() CLONE.Parent = Player.Backpack game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value - 1000 appleInInv = true else if appleInInv == true then print("you already have this item!") else if game.Players.LocalPlayer.leaderstats.Cash.Value < 1000 then print("not enough money!") end end end end)

1 answer

✓ Accepted answer

You are cloning the tool with a LocalScript, meaning that it only clones client-sided, meaning that any server scripts in the tool will not work. So, you need to find a way to clone it with a server script. If I were to suggest a way to do that, I would say to use RemoteEvents (https://developer.roblox.com/en-us/api-reference/class/RemoteEvent).

2 comments

0

Could I just write the tool script as a local script?

0

You could, but that still wouldn't make it to where the tool is cloned to your backpack.

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