Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can anyone help me on this Small error with a script for Starter player animation?

Having a problem when trying to add a default idle animation for my starter player using the script.

The error message is this: Players.abelgetachew19.PlayerScripts.AnimationHandles:4: attempt to index nil with 'Humanoid' - Client - Animation Handles:4



local FloatingIdle = script.Floating
local player = game.Players.LocalPlayer
local char = player.Character
local hum = char.Humanoid

local FloatingAnimation = hum:LoadAnimation(FloatingIdle)

game.Players.PlayerAdded:Connect(function(startanimation)
	if startanimation == true then
		FloatingAnimation:Play()
	end
end)

1 answer

✓ Accepted answer

Add a :WaitForChild() to the variable hum

local FloatingIdle = script.Floating
local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")

local FloatingAnimation = hum:LoadAnimation(FloatingIdle)

game.Players.PlayerAdded:Connect(function(startanimation)
    if startanimation == true then
        FloatingAnimation:Play()
    end
end)

3 comments

0

I'm getting a new error message: "attempt to index nil with 'WaitForChild'"

0

it's a server script as i understand it. grab the character and the humanoid from the .PlayerAdded event. Also replace "startanimation" with the player (.PlayerAdded only returns the new player)

0

It fixed the error but the script won't run at all. I give up

This discussion is preserved as it was. New answers, comments, and votes are closed.