A regular debounce won’t do anything, as it would be local to the new script’s environment. remember, the AncestryChanged connection isn’t the same connection for every tool, but rather each tool makes its own isolated connection, so the debounce applied in one script only affects that script and no others. Ideally, a method to disconnect the event after it has fired once should be implemented, so that tools aren’t spawned everytime the player unequips the tool, something like this:
local Connection
Connection = script.Parent.AncestryChanged:Connect(function()
if not script.Parent:IsDescendantOf(workspace) then
BackUp.Parent = workspace
Connection:Disconnect()
end
end)
This will make the function disconnect its own connection when it is called, preventing multiple from spawning from the same tool.
The BoolValue allows other scripts to more easily influence the script in the tool. It initially starts off, then proceeds when given the go ahead by another script when its supposed to, in this case the script that cloned it, as it is controlling the flow of events and knows when is the right time to let the script do its thing so that it doesn’t break anything, like so:
local Connection
Connection = script.Parent.AncestryChanged:Connect(function()
if not script.Parent:IsDescendantOf(workspace) then
BackUp.Parent = workspace
BackUp:WaitForChild("Script"):WaitForChild("run").Value = true
Connection:Disconnect()
end
end)
this will make sure that the new script only makes the ancestry changed connection when it is sure that it is in the right spot to not fire it immediately.
It should be noted that with this method, the script needs a new, completely unrelated script to get the original tool working, as it doesn’t have anything currently to check off run for it. You could get around this by starting with run as True, but set it to False after the check but before cloning the backup, so that the backup doesn’t run immediately:
if not run.Value then
run:GetPropertyChangedSignal("Value"):Wait()
end
run.Value = false
local BackUp = script.Parent:Clone()