Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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)
0
I'm getting a new error message: "attempt to index nil with 'WaitForChild'" abelgetachew19 -10 — 2y
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) FirewolfYT_751 223 — 2y
0
It fixed the error but the script won't run at all. I give up abelgetachew19 -10 — 2y
Ad

Answer this question