Load animation working only second time

Load animation is only working the second time it is ran. All other code works fine. And the animation says it is playing. The animation is on a rigged part. Here is code:


local function Animation(Chest, state)
	local OpenAnim = Chest.Animations:WaitForChild("Open")
	local controller = Chest.AnimationController
	local prompt = Chest.Extra.Union.ProximityPrompt

	local Open = controller:LoadAnimation(OpenAnim)

	
	if state == "start" then
		print(state) -- prints start
		prompt.Enabled = false
		Open:Play()
		task.delay(Open.Length-.01, function()
			Open:AdjustSpeed(0)
		end)
	-- ignore this:	
		local open = game.ReplicatedStorage.Sounds.ChestOpenSound:Clone()
		open.Parent = Chest.UI
		open:Play()
		if not open.Playing then
			open:Destroy()
			open = nil
		end
	else
		prompt.Enabled = true
		local close = game.ReplicatedStorage.Sounds.ChestCloseSound:Clone()
		close.Parent = Chest.UI
		close:Play()
		Open:AdjustSpeed(1)
		if not close.Playing then
			close:Destroy()
			close = nil
		end
	end
end

Any help would be awesome. Also the main problem seems to be only at the load animation part

AnimationController:loadanimation is deprecated try using animator instead
i hope that helps

1 Like

what is animator? i dont understand please explain more

Hi! Here is a post explaining the animator: Animator | Documentation - Roblox Creator Hub. Essentially, the animator is a class inside the humanoid responsible for playing and replicating animations.

1 Like

wow ty for this i switched to it but nothing works :frowning:

Please attach a photo of how you used Animator in your script.

1 Like

i unfortunetly cant cuz this pc is so garbage. but i have the animation controller and animation both in a folder, and under the controller is the animator

Paste code then, just copy it from the script and paste it in here. use preformatted text to organize it.