LoadAnimation Requires the Humanoid Object

  1. What do you want to achieve?

Probably better source code of my Animation Handler, but I just want me animations to not break after reset.

  1. What is the issue?

When a player resets, they aren’t able to use the dancegui anymore.

The dancegui does have RESETONSPAWN to FALSE, because Im using TOPBARGUI.

  1. What solutions have you tried so far?

I tried my best, bust none resolved…

Website 1
Website 2
Website 3

I tried putting this in my code -

while char.Parent == nil do
	char.AncestryChanged:wait()
end
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
repeat wait() until humanoid:IsDescendantOf(game)

Here is the whole script -

-- Locals for the animations.

wait(1)

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
repeat wait() until humanoid:IsDescendantOf(game)

local frame=script.Parent
local frame2 = script.Parent.Parent.Page2
local anim
local Sound = script.Parent.Parent.Parent.Parent.Parent.Sound

-- Function for playing the animations.

function playanim(id)
	
	if char~=nil and humanoid ~= nil then
		local id="rbxassetid://"..tostring(id)
		local oldanim=char:FindFirstChild("LocalAnimation")
		if anim~=nil then
			anim:Stop()
		end
		if oldanim~=nil then
			if oldanim.AnimationId==id then
				oldanim:Destroy()
				return
			end
			oldanim:Destroy()
		end
		local animation=Instance.new("Animation",char)
		animation.Name="LocalAnimation"
		animation.AnimationId=id
		anim=humanoid:LoadAnimation(animation)
		anim:Play()
	end
	
end

-- This is where you add more of your buttons and dances.. Just copy and paste. Make sure to change the b's.

-- PAGE 1
local b1=frame.Button1
b1.MouseButton1Down:connect(function() playanim(b1.AnimID.Value) Sound:Play() end)
local b2=frame.Button2
b2.MouseButton1Down:connect(function() playanim(b2.AnimID.Value) Sound:Play() end)
local b3=frame.Button3
b3.MouseButton1Down:connect(function() playanim(b3.AnimID.Value) Sound:Play() end)
local b4=frame.Button4
b4.MouseButton1Down:connect(function() playanim(b4.AnimID.Value) Sound:Play() end)
local b5=frame.Button5
b5.MouseButton1Down:connect(function() playanim(b5.AnimID.Value) Sound:Play() end)
local b6=frame.Button6
b6.MouseButton1Down:connect(function() playanim(b6.AnimID.Value) Sound:Play() end)
local b7=frame.Button7
b7.MouseButton1Down:connect(function() playanim(b7.AnimID.Value) Sound:Play() end)

-- PAGE 2
local b1=frame2.Button1
b1.MouseButton1Down:connect(function() playanim(b1.AnimID.Value) Sound:Play() end)
local b2=frame2.Button2
b2.MouseButton1Down:connect(function() playanim(b2.AnimID.Value) Sound:Play() end)
local b3=frame2.Button3
b3.MouseButton1Down:connect(function() playanim(b3.AnimID.Value) Sound:Play() end)
local b4=frame2.Button4
b4.MouseButton1Down:connect(function() playanim(b4.AnimID.Value) Sound:Play() end)
local b5=frame2.Button5
b5.MouseButton1Down:connect(function() playanim(b5.AnimID.Value) Sound:Play() end)
local b6=frame2.Button6
b6.MouseButton1Down:connect(function() playanim(b6.AnimID.Value) Sound:Play() end)
local b7=frame2.Button7
b7.MouseButton1Down:connect(function() playanim(b7.AnimID.Value) Sound:Play() end)

Any ideas?

humanoid:LoadAnimation is deprecated, you should be using Animator:LoadAnimation instead.

1 Like

I used that, thankyou for reminding me about Animator.

Any idea still? It didn’t fix it.

Unfortunately not, one question though. Why are you destroying the animation and then creating it again?

Whenever the player dies, the players humanoid changes so you’ll need to re-define your humanoid each time.

Add this after local humanoid = char:WaitForChild("Humanoid")

player.CharacterAdded:Connect(function(Character)
  humanoid = Character:WaitForChild("Humanoid")
end)

What this does is ensures that whenever the player dies and respawns, we set the humanoid variable to the new humanoid. This is so further animations will be loaded onto the new one instead of the old one which no longer exists.

1 Like

That’s kinda what I mentioned up top.

I want a better way of this source code but.

Any advice is helpful!

Not really related to your problem but you could clean up your code on the bottom where it plays the animations. Instead of doing them one by one you can use a loop.

for i, button in pairs(frame:GetChildren()) do
	if button:IsA("TextButton") then
		button.MouseButton1Down:Connect(function() 
			playanim(button.AnimID.Value) 
			Sound:Play() 
		end)
	end
end

Same thing for page 2 or you can put all the pages under one frame, and loop through them.

1 Like