I'm going to try to explain this the best I can.
I'm trying to make a script so that when you die, it plays an animation before you actually "die."
Now, this script works perfectly the first time. The player reaches 0 health and the animation plays.
My problem is that when I try to play it the second time, the animation starts but it stops itself instantly after? Anybody know why this happens?
And before anyone says: Yes, I know :LoadAnimation() is deprecated. And yes, the animation priority is above Core. I even made it so it pauses so the animation doesn't move anymore. But it only pauses the first time around. Not the second time. I've been having this problem for a while. I've been researching ways to try and fix it but I just can't figure it out. Can anyone help me?
Here's the script:
(Server script in ServerScriptService)
local replicatedStorage = game:GetService("ReplicatedStorage")
local dead = replicatedStorage:WaitForChild("Death")
local debounce = false
dead .OnServerEvent:Connect(function(player, enemy)
print("Recieved event")
if not debounce then
debounce = true
local character = player.Character
local enemyplr = game.Players:GetPlayerFromCharacter(enemy)
character.HumanoidRootPart.Anchored = true
enemy.HumanoidRootPart.Anchored = true
local Track1 = player.Character.Humanoid:LoadAnimation(script.DeathAnim)
Track1:Play()
print("played animation")
wait(3)
debounce = false
enemy.Humanoid.BreakJointsOnDeath = true
enemyplr:LoadCharacter()
character.HumanoidRootPart.Anchored = false
end
end)
Second server script in ServerScriptService(Defines the animations)
local players = game:GetService("Players")
players.RespawnTime = 30
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
wait()
c.Humanoid:WaitForChild("Animator")
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://MYANIMATIONIDISHERE" -- Yes, I'm aware that it says this. I only put that here for the purpose of the showcase.
local PlayAnim = c.Humanoid:LoadAnimation(Anim)
local canbegripped = Instance.new("BoolValue")
canbegripped.Name = "CanBeGripped"
canbegripped.Value = false
canbegripped.Parent = c
c.Humanoid.BreakJointsOnDeath = false
c.Humanoid.Died:Connect(function(deadplayer)
c.Humanoid:WaitForChild("Animator")
PlayAnim:Play()
c.HumanoidRootPart.Anchored = true
wait(.85)
PlayAnim:AdjustSpeed(0)
canbegripped.Value = true
c.HumanoidRootPart.CanCollide = false
end)
end)
end)
