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)