So recently i make a script that runs an animation when a tool is activated but when a player dies, the animation stops working. Here’s the script:
local Tool = script.Parent
local Player = game.Players.LocalPlayer -- Get local player
local Chr = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Chr:WaitForChild("Humanoid")
local debounce = true
while Humanoid and not Humanoid:IsDescendantOf(workspace) do
Humanoid.AncestryChanged:Wait()
end
local Animation = Tool.Animation
local Animator = Humanoid:WaitForChild("Animator")
local AnimTrack = Animator:LoadAnimation(Animation)
Tool.Activated:Connect(function()
if debounce then-- Mouse is NOT passed, that's Equipped
AnimTrack:Play()
debounce = false
wait(1)
debounce = true
end
end)
Is something wrong with the script? I don’t understand why it stops working after a player dies.
There are probably 2 reasons. One reason is because the character’s BreaksJointOnDeath is set to true. Another reason is because you have a ragdoll script, I think. I don’t think there is something wrong with the script.
Alright, it’s night time for me so I’m telling this short.
You should have a Tool.Equipped event for the script to know when do u trigger it. Inside of the Equipped event, put Tool:Activated() function to tell the script that Activated only work when a tool is equipped. Then do the same thing for Activated event. If it still doesnt work, try putting prints in certain parts of the script to check what’s not working. I have no clue what were u trying to do in the “while Humanoid” and changing debounce vars in tool.activated
local Tool = script.Parent
local Player = game.Players.LocalPlayer -- Get local player
local Chr = Player.Character
if Chr == nil or Chr.Parent ~= game:GetService("Workspace") then
Chr = Player.CharacterAdded:Wait()
end
local Humanoid = Chr:WaitForChild("Humanoid")
local debounce = true
while Humanoid and not Humanoid:IsDescendantOf(workspace) do
Humanoid.AncestryChanged:Wait()
end
local Animation = Tool.Animation
local Animator = Humanoid:WaitForChild("Animator")
local AnimTrack = Animator:LoadAnimation(Animation)
Tool.Activated:Connect(function()
if debounce then-- Mouse is NOT passed, that's Equipped
AnimTrack:Play()
debounce = false
wait(1)
debounce = true
end
end)