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

[Easy?] Local animation player fix

Please note This game is R6 , this animation is valid, and this is a local script, and i want it to be a local script, ive seen another script use this animation locally and it worked, but i think im playing it incorrectly, any help would be highly appreciated thanks!

local plr = game:GetService('Players').LocalPlayer
local char = plr.Character
local Humanoid = char:WaitForChild('Humanoid')
local ROBLOXIDLEANIMATION = Instance.new("Animation")
ROBLOXIDLEANIMATION.Name = "Roblox Idle Animation"
ROBLOXIDLEANIMATION.AnimationId = "http://www.roblox.com/asset/?id=180435571"

    local IDLEANIMATION = Humanoid:LoadAnimation(ROBLOXIDLEANIMATION)
	IDLEANIMATION.Looped = true
    IDLEANIMATION:Play()

1 answer

✓ Accepted answer

You seem to have edited your post to fit the code in my solution, but appear it appears to have not worked so I'll just edit my post.

#Issues There are a few potential issues.

  • Character may not exist yet
  • Character may not be a descendant of game yet

##Character may not exist yet

Character does not exist yet, so you need to wait for it to exist.

Can be done easily with something along the lines of local char = player.Character or player.CharacterAdded:Wait()

##Character may not be a descendant of game yet

You will want to wait for it to exist. Can be done quickly with :IsDescendantOf and a repeat until loop.

repeat wait() until Humanoid:IsDescendantOf(game)

#P.S. Before he edited his post:

You're constantly replaying the animation via :Play() This means the animation will keep resetting.

If you want your animation to loop set the Looped property to true.

https://developer.roblox.com/en-us/api-reference/property/AnimationTrack/Looped

local IDLEANIMATION = Humanoid:LoadAnimation(ROBLOXIDLEANIMATION)

IDLEANIMATION.Looped = true
IDLEANIMATION:Play()

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