Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

(FIXED) Tool script stops working after player dies?

Asked by 6 years ago
Edited 6 years ago
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local tool = script.Parent
local dmg = tool:WaitForChild("Damage")
local sword = tool:WaitForChild("Sword")
local swordblade = sword:WaitForChild("Blade")
local trail = swordblade:WaitForChild("Trail")
local handle = tool:WaitForChild("Handle")
local swing = handle:WaitForChild("Swing")
local switch = tool:WaitForChild("CanAttack")

tool.Equipped:connect(function()
    local hum = char:WaitForChild("Humanoid")
    local idle = hum:LoadAnimation(script.Idle)
    idle:Play()
end)

tool.Activated:connect(function()
    local hum = char:WaitForChild("Humanoid")
    dmg.Disabled = false
    switch.Value = true
    local choose = math.random(1,3)
    if choose == 1 then
        local swing1 = hum:LoadAnimation(script.Swing1)
        swing1:Play()
        swing:Play()
        trail.Enabled = true
    elseif choose == 2 then
        local swing2 = hum:LoadAnimation(script.Swing2)
        swing2:Play()
        swing:Play()
        trail.Enabled = true
    elseif choose == 3 then
        local swing3 = hum:LoadAnimation(script.Swing3)
        swing3:Play()
        swing:Play()
        trail.Enabled = true
    end
end)

tool.Deactivated:connect(function()
    dmg.Disabled = true
    wait(2)
    switch.Value = false
    trail.Enabled = false
end)

tool.Unequipped:connect(function()
    local hum = char:WaitForChild("Humanoid")
    for _,anim in pairs(hum:GetPlayingAnimationTracks()) do
        anim:Stop()
    end
end)

The sword is in the StarterPack. The sword works in studio but in game when a player dies, it stops working with an error:

"LoadAnimation requires the Humanoid object (InfernoExeuctioner.Humanoid) to be a descendant of the game object".

What does that mean and how to I fix it?

0
Is the tool replaced with a new one every time the player dies? RayCurse 1518 — 6y
0
yes InfernoExeuctioner 126 — 6y
0
Never mind, I fixed it just had to replace every time it was defining the humanoid with script.Parent.Parent.Humanoid. InfernoExeuctioner 126 — 6y

Answer this question