Tool Stops working after being cloned to the Player's BackPack

Basicly, Im trying to make a Sword game simular to slap battles (if you know) and everything was going well until i decided to make a gui instead of a lobby…

There wasn’t any real problems until i made the button to select the first sword that will Clone the sword from a folder in RS (Replicated Storage) to your inventory and remove the gui but guess what happened? I cloned the sword and the sword stopped working just like a computer crash, it just didn’t swing and activate it’s ability just like if it was a disabled script, and then it just stopped working entirely even after i put in in StarterPack

So the actual problem might be the scripts that the sword contains or a bug with roblox studio (80% not) and i tried looking for any errors, try any solutions as a beginner developer and even look on the dev forums but i gained nothing from that (also Youtube is obviously not gonna work, as its not made for the same objective as the Dev Forums) So im making this post to see if anybody could atleast report whats wrong and how i could fix it.

Also the sword is a modified version of the classic sword

  • Script (Sword, in RS, disabled)
    Tool = script.Parent
    local SOwner = Tool.Parent.Parent
    Handle = Tool:WaitForChild(“Handle”)
    local AbilityEvent = game:GetService(“ReplicatedStorage”).Remotes.AbilityEvent

    local plr = Tool.Parent.Parent
    local char = plr.CharacterAdded:Wait()

    function Create(ty)
    return function(data)
    local obj = Instance.new(ty)
    for k, v in pairs(data) do
    if type(k) == ‘number’ then
    v.Parent = obj
    else
    obj[k] = v
    end
    end
    return obj
    end
    end

    local BaseUrl = “rbxassetid://”

    Players = game:GetService(“Players”)
    Debris = game:GetService(“Debris”)
    RunService = game:GetService(“RunService”)

    DamageValues = {
    BaseDamage = 0,
    SlashDamage = 3,
    LungeDamage = 2,
    }

    –For R15 avatars
    Animations = {
    R15Slash = 522635514,
    R15Lunge = 522638767
    }

    Damage = DamageValues.BaseDamage

    Grips = {
    Up = CFrame.new(0, 0, -1.70000005, 0, 0, 1, 1, 0, 0, 0, 1, 0),
    Out = CFrame.new(0, 0, -1.70000005, 0, 1, 0, 1, -0, 0, 0, 0, -1)
    }

    Sounds = {
    Slash = Handle:WaitForChild(“SwordSlash”),
    Lunge = Handle:WaitForChild(“SwordLunge”),
    Unsheath = Handle:WaitForChild(“Unsheath”)
    }

    ToolEquipped = false

    –For Omega Rainbow Katana thumbnail to display a lot of particles.
    for i, v in pairs(Handle:GetChildren()) do
    if v:IsA(“ParticleEmitter”) then
    v.Rate = 20
    end
    end

    Tool.Grip = Grips.Up
    Tool.Enabled = true

    function IsTeamMate(Player1, Player2)
    return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor)
    end

    function TagHumanoid(humanoid, player)
    local Creator_Tag = Instance.new(“ObjectValue”)
    Creator_Tag.Name = “creator”
    Creator_Tag.Value = player
    Debris:AddItem(Creator_Tag, 2)
    Creator_Tag.Parent = humanoid
    end

    function UntagHumanoid(humanoid)
    for i, v in pairs(humanoid:GetChildren()) do
    if v:IsA(“ObjectValue”) and v.Name == “creator” then
    v:Destroy()
    end
    end
    end

    function Blow(Hit)
    if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then
    return
    end
    local RightArm = Character:FindFirstChild(“Right Arm”) or Character:FindFirstChild(“RightHand”)
    if not RightArm then
    return
    end
    local RightGrip = RightArm:FindFirstChild(“RightGrip”)
    if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
    return
    end
    local character = Hit.Parent
    if character == Character then
    return
    end
    local humanoid = character:FindFirstChildOfClass(“Humanoid”)
    if not humanoid or humanoid.Health == 0 then
    return
    end
    local player = Players:GetPlayerFromCharacter(character)
    if player and (player == Player or IsTeamMate(Player, player)) then
    return
    end
    UntagHumanoid(humanoid)
    TagHumanoid(humanoid, Player)
    humanoid:TakeDamage(Damage)
    SOwner.leaderstats.Damage.Value = SOwner.leaderstats.Damage.Value + 0.1
    end

    function Attack()
    Damage = DamageValues.SlashDamage
    Sounds.Slash:Play()

      if Humanoid then
      	if Humanoid.RigType == Enum.HumanoidRigType.R6 then
      		local Anim = Instance.new("StringValue")
      		Anim.Name = "toolanim"
      		Anim.Value = "Slash"
      		Anim.Parent = Tool
      	elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
      		local Anim = Tool:FindFirstChild("R15Slash")
      		if Anim then
      			local Track = Humanoid:LoadAnimation(Anim)
      			Track:Play(0)
      		end
      	end
      end	
    

    end

    function Lunge()
    Damage = DamageValues.LungeDamage

      Sounds.Lunge:Play()
    
      if Humanoid then
      	if Humanoid.RigType == Enum.HumanoidRigType.R6 then
      		local Anim = Instance.new("StringValue")
      		Anim.Name = "toolanim"
      		Anim.Value = "Lunge"
      		Anim.Parent = Tool
      	elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
      		local Anim = Tool:FindFirstChild("R15Lunge")
      		if Anim then
      			local Track = Humanoid:LoadAnimation(Anim)
      			Track:Play(0)
      		end
      	end
      end	
    

    wait(0.2)
    Tool.Grip = Grips.Out
    wait(0.6)
    Tool.Grip = Grips.Up

      Damage = DamageValues.SlashDamage
    

    end

    Tool.Enabled = true
    LastAttack = 0

    function Activated()
    if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then
    return
    end
    Tool.Enabled = false
    local Tick = RunService.Stepped:wait()
    if (Tick - LastAttack < 0.2) then
    Lunge()
    else
    Attack()
    end
    LastAttack = Tick
    wait(0.5)
    Damage = DamageValues.BaseDamage
    local SlashAnim = (Tool:FindFirstChild(“R15Slash”) or Create(“Animation”){
    Name = “R15Slash”,
    AnimationId = BaseUrl … Animations.R15Slash,
    Parent = Tool
    })

      local LungeAnim = (Tool:FindFirstChild("R15Lunge") or Create("Animation"){
      	Name = "R15Lunge",
      	AnimationId = BaseUrl .. Animations.R15Lunge,
      	Parent = Tool
      })
      Tool.Enabled = true
    

    end

    function CheckIfAlive()
    return (((Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Torso and Torso.Parent) and true) or false)
    end

    function Equipped()
    Character = Tool.Parent
    Player = Players:GetPlayerFromCharacter(Character)
    Humanoid = Character:FindFirstChildOfClass(“Humanoid”)
    Torso = Character:FindFirstChild(“Torso”) or Character:FindFirstChild(“HumanoidRootPart”)
    if not CheckIfAlive() then
    return
    end
    ToolEquipped = true
    Sounds.Unsheath:Play()

    end

    function Unequipped()
    Tool.Grip = Grips.Up
    ToolEquipped = false
    end

    Tool.Activated:Connect(Activated)
    Tool.Equipped:Connect(Equipped)
    Tool.Unequipped:Connect(Unequipped)

    –Connection = Handle.Touched:Connect(Blow)
    Connection = Handle.Touched:Connect(Activated)

    AbilityEvent.OnServerEvent:Connect(function()

      Lunge()
    

    end)

  • Local Script (Sword, RS, Disabled)

Mouse_Icon = “rbxasset://textures/GunCursor.png”
Reloading_Icon = “rbxasset://textures/GunWaitCursor.png”
local uis = game:GetService(“UserInputService”)
local AbilityEvent = game:GetService(“ReplicatedStorage”).Remotes.AbilityEvent
local ACGUI = game:GetService(“StarterGui”).AbilityCooldownGUI
local CT = ACGUI.Background.CooldownText
local AbilityCooldown = game:GetService(“ReplicatedStorage”).Remotes.AbilityCooldown
local CooldownValue = game:GetService(“ReplicatedStorage”).CooldownValue
Tool = script.Parent

local Cooldown = false

Mouse = nil

function UpdateIcon()
if Mouse then
Mouse.Icon = Tool.Enabled and Mouse_Icon or Reloading_Icon
end
end

function OnEquipped(ToolMouse)
Mouse = ToolMouse
UpdateIcon()
end

function OnChanged(Property)
if Property == “Enabled” then
UpdateIcon()
end
end

Tool.Equipped:Connect(OnEquipped)
Tool.Changed:Connect(OnChanged)

uis.InputBegan:Connect(function(inp, proc)
if proc then return end

if inp.KeyCode == Enum.KeyCode.E and Cooldown == false then
	if Tool.Equipped then
		AbilityEvent:FireServer()
		print("e")
		Cooldown = true

		for i = 4,1,-1 do
			CooldownValue.Value = i
			wait(1)

		end

		CooldownValue.Value = ""
		Cooldown = false
	end
end

end)

  • LocalScript (GUIButton, StarterGui

local Player = game:GetService(“Players”).LocalPlayer
local Damage = Player.leaderstats.Damage
local Button = script.Parent
local Menu = game:GetService(“StarterGui”).Menu.Selection
local SwordsFolder = game:GetService(“ReplicatedStorage”).Swords

local Character = game:GetService(“Players”).LocalPlayer.Character
local Humanoid = Character.Humanoid

Button.Activated:Connect(function()

if Damage.Value >= 0 then
	
	script.Parent.Parent.Parent.Parent.Visible = false
	local Sword = SwordsFolder["Classic Sword"]:Clone()
	Sword.Parent = Player.Backpack
	task.wait(0.05)
	Sword.SwordScript.Enabled = true
	Sword.LocalSwordScript.Enabled = true
end

Humanoid.Died:Connect(function()
	
	task.wait(3)
	script.Parent.Parent.Parent.Parent.Visible = true
	
end)

end)

Notes:

  • Remote events are in a folder called “Remotes” in RS

  • The Sword is in a folder called “Swords” in RS

Please fix the code blocks. It is very difficult to read.

Try disabling the main code and enabling it with the script that gives the tool.
WaitForChild will yield an infinite wait because it cannot find the desired instances while in the backpack

Here you go

Tool = script.Parent
local SOwner = Tool.Parent.Parent
Handle = Tool:WaitForChild(“Handle”)
local AbilityEvent = game:GetService(“ReplicatedStorage”).Remotes.AbilityEvent

local plr = Tool.Parent.Parent
local char = plr.CharacterAdded:Wait()

function Create(ty)
return function(data)
local obj = Instance.new(ty)
for k, v in pairs(data) do
if type(k) == ‘number’ then
v.Parent = obj
else
obj[k] = v
end
end
return obj
end
end

local BaseUrl = “rbxassetid://”

Players = game:GetService(“Players”)
Debris = game:GetService(“Debris”)
RunService = game:GetService(“RunService”)

DamageValues = {
BaseDamage = 0,
SlashDamage = 3,
LungeDamage = 2,
}

–For R15 avatars
Animations = {
R15Slash = 522635514,
R15Lunge = 522638767
}

Damage = DamageValues.BaseDamage

Grips = {
Up = CFrame.new(0, 0, -1.70000005, 0, 0, 1, 1, 0, 0, 0, 1, 0),
Out = CFrame.new(0, 0, -1.70000005, 0, 1, 0, 1, -0, 0, 0, 0, -1)
}

Sounds = {
Slash = Handle:WaitForChild(“SwordSlash”),
Lunge = Handle:WaitForChild(“SwordLunge”),
Unsheath = Handle:WaitForChild(“Unsheath”)
}

ToolEquipped = false

–For Omega Rainbow Katana thumbnail to display a lot of particles.
for i, v in pairs(Handle:GetChildren()) do
if v:IsA(“ParticleEmitter”) then
v.Rate = 20
end
end

Tool.Grip = Grips.Up
Tool.Enabled = true

function IsTeamMate(Player1, Player2)
return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor)
end

function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new(“ObjectValue”)
Creator_Tag.Name = “creator”
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end

function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA(“ObjectValue”) and v.Name == “creator” then
v:Destroy()
end
end
end

function Blow(Hit)
if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then
return
end
local RightArm = Character:FindFirstChild(“Right Arm”) or Character:FindFirstChild(“RightHand”)
if not RightArm then
return
end
local RightGrip = RightArm:FindFirstChild(“RightGrip”)
if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
return
end
local character = Hit.Parent
if character == Character then
return
end
local humanoid = character:FindFirstChildOfClass(“Humanoid”)
if not humanoid or humanoid.Health == 0 then
return
end
local player = Players:GetPlayerFromCharacter(character)
if player and (player == Player or IsTeamMate(Player, player)) then
return
end
UntagHumanoid(humanoid)
TagHumanoid(humanoid, Player)
humanoid:TakeDamage(Damage)
SOwner.leaderstats.Damage.Value = SOwner.leaderstats.Damage.Value + 0.1
end

function Attack()
Damage = DamageValues.SlashDamage
Sounds.Slash:Play()

  if Humanoid then
  	if Humanoid.RigType == Enum.HumanoidRigType.R6 then
  		local Anim = Instance.new("StringValue")
  		Anim.Name = "toolanim"
  		Anim.Value = "Slash"
  		Anim.Parent = Tool
  	elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
  		local Anim = Tool:FindFirstChild("R15Slash")
  		if Anim then
  			local Track = Humanoid:LoadAnimation(Anim)
  			Track:Play(0)
  		end
  	end
  end	
end

function Lunge()
Damage = DamageValues.LungeDamage

  Sounds.Lunge:Play()

  if Humanoid then
  	if Humanoid.RigType == Enum.HumanoidRigType.R6 then
  		local Anim = Instance.new("StringValue")
  		Anim.Name = "toolanim"
  		Anim.Value = "Lunge"
  		Anim.Parent = Tool
  	elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
  		local Anim = Tool:FindFirstChild("R15Lunge")
  		if Anim then
  			local Track = Humanoid:LoadAnimation(Anim)
  			Track:Play(0)
  		end
  	end
  end	
wait(0.2)
Tool.Grip = Grips.Out
wait(0.6)
Tool.Grip = Grips.Up

  Damage = DamageValues.SlashDamage
end

Tool.Enabled = true
LastAttack = 0

function Activated()
if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then
return
end
Tool.Enabled = false
local Tick = RunService.Stepped:wait()
if (Tick - LastAttack < 0.2) then
Lunge()
else
Attack()
end
LastAttack = Tick
wait(0.5)
Damage = DamageValues.BaseDamage
local SlashAnim = (Tool:FindFirstChild(“R15Slash”) or Create(“Animation”){
Name = “R15Slash”,
AnimationId = BaseUrl … Animations.R15Slash,
Parent = Tool
})

  local LungeAnim = (Tool:FindFirstChild("R15Lunge") or Create("Animation"){
  	Name = "R15Lunge",
  	AnimationId = BaseUrl .. Animations.R15Lunge,
  	Parent = Tool
  })
  Tool.Enabled = true
end

function CheckIfAlive()
return (((Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Torso and Torso.Parent) and true) or false)
end

function Equipped()
Character = Tool.Parent
Player = Players:GetPlayerFromCharacter(Character)
Humanoid = Character:FindFirstChildOfClass(“Humanoid”)
Torso = Character:FindFirstChild(“Torso”) or Character:FindFirstChild(“HumanoidRootPart”)
if not CheckIfAlive() then
return
end
ToolEquipped = true
Sounds.Unsheath:Play()

end

function Unequipped()
Tool.Grip = Grips.Up
ToolEquipped = false
end

Tool.Activated:Connect(Activated)
Tool.Equipped:Connect(Equipped)
Tool.Unequipped:Connect(Unequipped)

–Connection = Handle.Touched:Connect(Blow)
Connection = Handle.Touched:Connect(Activated)

AbilityEvent.OnServerEvent:Connect(function()

  Lunge()
end)

Local Script (Sword, RS, Disabled)

Mouse_Icon = “rbxasset://textures/GunCursor.png”
Reloading_Icon = “rbxasset://textures/GunWaitCursor.png”
local uis = game:GetService(“UserInputService”)
local AbilityEvent = game:GetService(“ReplicatedStorage”).Remotes.AbilityEvent
local ACGUI = game:GetService(“StarterGui”).AbilityCooldownGUI
local CT = ACGUI.Background.CooldownText
local AbilityCooldown = game:GetService(“ReplicatedStorage”).Remotes.AbilityCooldown
local CooldownValue = game:GetService(“ReplicatedStorage”).CooldownValue
Tool = script.Parent

local Cooldown = false

Mouse = nil

function UpdateIcon()
if Mouse then
Mouse.Icon = Tool.Enabled and Mouse_Icon or Reloading_Icon
end
end

function OnEquipped(ToolMouse)
Mouse = ToolMouse
UpdateIcon()
end

function OnChanged(Property)
if Property == “Enabled” then
UpdateIcon()
end
end

Tool.Equipped:Connect(OnEquipped)
Tool.Changed:Connect(OnChanged)

uis.InputBegan:Connect(function(inp, proc)
if proc then return end

if inp.KeyCode == Enum.KeyCode.E and Cooldown == false then
	if Tool.Equipped then
		AbilityEvent:FireServer()
		print("e")
		Cooldown = true

		for i = 4,1,-1 do
			CooldownValue.Value = i
			wait(1)

		end

		CooldownValue.Value = ""
		Cooldown = false
	end
end
end)

LocalScript (GUIButton, StarterGui
local Player = game:GetService(“Players”).LocalPlayer
local Damage = Player.leaderstats.Damage
local Button = script.Parent
local Menu = game:GetService(“StarterGui”).Menu.Selection
local SwordsFolder = game:GetService(“ReplicatedStorage”).Swords

local Character = game:GetService(“Players”).LocalPlayer.Character
local Humanoid = Character.Humanoid

Button.Activated:Connect(function()

if Damage.Value >= 0 then
	
	script.Parent.Parent.Parent.Parent.Visible = false
	local Sword = SwordsFolder["Classic Sword"]:Clone()
	Sword.Parent = Player.Backpack
	task.wait(0.05)
	Sword.SwordScript.Enabled = true
	Sword.LocalSwordScript.Enabled = true
end

Humanoid.Died:Connect(function()
	
	task.wait(3)
	script.Parent.Parent.Parent.Parent.Visible = true
	
end)
end)