Death Animation doesnt load sometimes

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Avoid the death animation script from bugging out
(freezing)

  1. What is the issue? Include screenshots / videos if possible!

https://streamable.com/szett1

When Dying sometimes the death animation can take 20 seconds to play

The script is one a threw together with help of AI and tweaking it myself

Serverscript:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
		local humanoid = character:WaitForChild("Humanoid")
		local animationId = "15223668638"
		

		humanoid.BreakJointsOnDeath = false

		humanoid.Died:Connect(function()
			humanoid.Health = 0

			local animation = Instance.new("Animation")
			animation.AnimationId = "rbxassetid://" .. animationId
			humanoid:LoadAnimation(animation):Play()
			humanoidRootPart.Anchored = true

		end)
	end)
end)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Changing Serverscript to local
preloading animation

local animation = Instance.new("Animation")
animation.Parent = script
animation.AnimationId = "rbxassetid://15223668638"
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
		local humanoid = character:WaitForChild("Humanoid")
		local animator = humanoid.Animator
		local track = animator:LoadAnimation(animation)

		humanoid.BreakJointsOnDeath = false

		humanoid.Died:Connect(function()
			humanoid.Health = 0
			track:Play()
			humanoidRootPart.Anchored = true

		end)
	end)
end)

Try preloading it but with animator like I did in above script.

From that i get:

17:49:30.681 Cannot load the AnimationClipProvider Service. - Server - DeathScript:9

In a local script do:
(animations do replicate to server in local scripts)

Make sure animation is already an instance you made.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local animator = humanoid:WaitForChild("Animator")
local animation = script:WaitForChild("DeathAnim")
local track = animator:LoadAnimation(animation)

humanoid.Died:Connect(function()
	track:Play()
	humanoidRootPart.Anchored = true
end)
1 Like

Due to an issue where doing humanoidRootPart.Anchored = true locally
should i fire a remote event to do that bit server side?

Why are you setting humanoidrootpart.Anchored to true anyways?

since when the player dies the animation makes the player move around on the ground
also am planning of making an orb go around the player for respawning effect so freezing the player in the air would be ideal for that

Oh if so then you dont need to replicate anchored to the server because player movement replicates on the server so technically nothing would happen.

Managed to get it working using this solution and some serverside code

Local:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local humanoidRootPart = char:WaitForChild("HumanoidRootPart")
local animator = humanoid:WaitForChild("Animator")
local animation = script:WaitForChild("DeathAnim")
local track = animator:LoadAnimation(animation)
local replicatedstorage = game:GetService("ReplicatedStorage")
local deathevent = replicatedstorage:WaitForChild("PlayerDeath")


humanoid.BreakJointsOnDeath = false

humanoid.Died:Connect(function()
	deathevent:FireServer(player)
	track:Play()
	task.wait(track.Length - 1.30)
	print("Animation Paused")
	track:AdjustSpeed(0)
end)

Serverside

local replicatedstorage = game:GetService("ReplicatedStorage")
local deathevent = replicatedstorage:WaitForChild("PlayerDeath")

deathevent.OnServerEvent:Connect(function(player)
	print("Event Found!")
	local char = player.Character or player.CharacterAdded:Wait()
	local humanoid = char:WaitForChild("Humanoid")
	local humanoidRootPart = char:WaitForChild("HumanoidRootPart")
	
	humanoidRootPart.Anchored = true
	wait(5) -- Wait Timer
	player:LoadCharacter()
end)

i have tried many times and it seems to not be freezing
(even if it did the player can now load instead of being stuck)

thanks for the help!

Cool! No probs!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.