Tool Breaks When Cloned From ServerStorage

I’m trying to make a tool that, when activated, deletes itself and replaces itself with another tool. The other tool does the same thing, replacing itself with the first tool. A copy of both tools are stored in ServerStorage, but when the first tool deletes itself and successfully replaces itself with the other tool from ServerStorage, it seems that the local script stops working in the newly cloned tool.

I’ve tried printing after the Tool.Activated function in the cloned tool, but it does not print to the console.

Both tools work independently when activated from StarterPack, but they do not work when stored and cloned from ServerStorage. If anyone has any idea why this is happening or can spot an error in my code, please let me know.

Local Script:

script.Parent.Activated:Connect(function()
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local ToggleBook = ReplicatedStorage:WaitForChild("ToggleBook")
	ToggleBook:FireServer(true)	
end)

Server Script:

local function onToggleBookFired(Player, Bool)
	
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local Humanoid = Character:FindFirstChild("Humanoid")
	local OpenBook = ServerStorage:WaitForChild("OpenBook"):Clone()
	local ClosedBook = ServerStorage:WaitForChild("ClosedBook"):Clone()

	if Bool == true then
		Character:FindFirstChildWhichIsA("Tool"):Destroy()		
		OpenBook.Parent = Player:WaitForChild("Backpack")
		OpenBook.Enabled = true
		OpenBook.LocalScript.Disabled = false
		Humanoid:EquipTool(OpenBook)

	elseif Bool == false then
		Character:FindFirstChildWhichIsA("Tool"):Destroy()		
		ClosedBook.Parent = Player:WaitForChild("Backpack")
		ClosedBook.Enabled = true
		ClosedBook.LocalScript.Disabled = false
		Humanoid:EquipTool(ClosedBook)
	end	
end
ToggleBook.OnServerEvent:Connect(onToggleBookFired)
2 Likes

I would suggest undisabling the localscript after you make them equip the tool.

It could quite work but I’m not too sure.

1 Like

Just tried that, but the same issue persists. No errors or anything, it seems like the tool just refuses to activate after being equipped through the server script, which is weird.

1 Like

Just found the issue, in the LocalScript, when cloned from ServerStorage, Character must be defined as

Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

NOT

Character = game.Players.LocalPlayer.CharacterAdded:Wait() or game.Players.LocalPlayer.Character

Furthermore, while I did not have to WaitForChild(“Animation”) in the tool from StarterPack, it was necessary to wait for the animation to load after cloning from ServerStorage.
There were no issues in the code I posted earlier.

1 Like