Exactly as the title says. No matter what I do to try to fix it, directly after death, the model reverts to the original T-Pose quickly before my animation is applied.
Here is what I mean:
Here is the server script that handles the animation:
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(char)
local anims = script:GetChildren()
local randomAnim = anims[math.random(1, #anims)] -- Select a random death animation
local animationTrack -- Variable to hold the animation track
local db = false
-- Preload the animation when the character spawns
local deathAnims = {
randomDeathAnim = hum:WaitForChild("Animator"):LoadAnimation(randomAnim)
}
local function deathCheck(health)
if hum.Health <= 0 then
if db == true then return end
db = true
-- Disable the default death state
hum:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
char:FindFirstChild("HumanoidRootPart").Anchored = true
char:FindFirstChild("HumanoidRootPart").Position += Vector3.new(0, 0.25, 0)
-- Stop all animations
for i, v in pairs(hum:GetPlayingAnimationTracks()) do
v:Stop()
end
-- Play custom death animation
deathAnims.randomDeathAnim:Play()
end
end
hum.HealthChanged:Connect(deathCheck)
I’ve been trying to fix this for a few hours now and I am completely stumped on what could be causing this, or even how to fix it. All help is greatly appreciated, thank you!
I would recommend using the .Died event on a humanoid, and also maybe Play the animation before stopping all the others:
– Stop all animations
– Play custom death animation
deathAnims.randomDeathAnim:Play()
for i, v in pairs(hum:GetPlayingAnimationTracks()) do
if v == deathAnims.randomDeathAnim then continue end
v:Stop()
end
Also no point really disabling default death state since the state had already become Dead
I appreciate the feedback and have revised my script using your feedback, but the problem still occurs with no visual difference. I’m totally stumped.
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(char)
local anims = script:GetChildren()
local randomAnim = anims[math.random(1, #anims)] -- Select a random death animation
local animationTrack -- Variable to hold the animation track
-- Preload the animation when the character spawns
local deathAnims = {
randomDeathAnim = hum:WaitForChild("Animator"):LoadAnimation(randomAnim)
}
hum.Died:Connect(function()
char:FindFirstChild("HumanoidRootPart").Anchored = true
char:FindFirstChild("HumanoidRootPart").Position += Vector3.new(0, 0.35, 0)
deathAnims.randomDeathAnim:Play()
-- Stop all animations besides the death animation
for i, v in pairs(hum:GetPlayingAnimationTracks()) do
if v == deathAnims.randomDeathAnim then continue end
v:Stop()
end
end)
Try run it on the client instead and see if its a latency issue instead, the client has network ownership so running the animations will still replicate.
The death animations were already priority Action4 and fading out animations with 0.2 fixed the replication to the server and other clients! Thank you!
But I still cannot respawn for some reason. It’s the exact same code in the server script, just put into a local script.
EDIT: I think I see the problem, I’m going to try to handle the anchoring of the HRP on the server.