Tool's Script doesn't work when I clone it

This post is in regards to something I’m creating. I was creating a Key (Tool) to open up a door.
I made it normally and it worked perfectly fine. However, every time I’d like to clone it into the LocalPlayer’s Backpack it goes there but the script or the sound doesn’t work.

I get no Error from the Output. When I put it in Workspace/StarterPack it works just fine!

-- Clone code. (I cut out a section of the whole code since it's messy)
local tool = game.ReplicatedStorage.Key:Clone()
tool.Parent = game.Players.LocalPlayer.Backpack

image

-- This is the Script located inside the Tool.
local tool = script.Parent
local sound = script.Sound
local Proxy = game.Workspace.ProximityPrompt

tool.Equipped:Connect(function(equipped)
	Proxy.HoldDuration = "1.5"
	Proxy.ActionText = "Unlock"
	Proxy.Script1.Disabled = false
	Proxy.Script.Disabled = true
	sound:Play()
end)

tool.Unequipped:Connect(function(unequipped)
	Proxy.HoldDuration = "0"
	Proxy.ActionText = "Locked"
	Proxy.Script1.Disabled = true
	Proxy.Script.Disabled = false
end)

Does anyone know why it just doesn’t work?
I tried to clone the Script and the Sound separately and it still doesn’t work.

Tested it myself just right now. Completely fine works, are you clonning the tool via local-script?

Oh I see now, yeah you did clone it using Local Script which you’re not supposed to do at all.
Instead, clone it using Server Script because Server still thinks that “Key” was never clonned at all inside player’s backpack since changes on client don’t replicate to the server.

2 Likes

You could also check for the script’s Ancestry changing and then start the code. I think scripts initiate in ReplicatedStorage too?

script.AncestryChanged:Wait()

Just that at the top should do.

1 Like