How to fix this animation loop?

Hi,
How can i fix this animation script? Script located at npc’s model

local anim = game.ReplicatedStorage.NPCAnim1
local humanoid = script.Parent.Humanoid
local Track = humanoid:LoadAnimation(anim1)


    if script.Parent.BoolValue.Value == true then
	    Track.Looped = true
	    Track:Play()
	end
	
	
	if script.Parent.BoolValue.Value == false then
		Track.Looped = false
		Track:Stop()
	end

Could you expain what’s wrong/what errors you’re getting in the output?

1 Like

What’s the problem with it?

I can’t see anything wrong with the code atm.

1 Like

no errors but its do not playing. its playing only once and then npc dont play animation

1 Like

You need to make the animation looped in the animation editor.

2 Likes

i noticed that this animation always plays at server but at client it plays ones, anyone know why?

2 Likes

Is the boolean value actually changing?

1 Like

Think you should add a while true do statement.

1 Like

Isn’t just making the animation looped better and less resource-intensive on the server?

1 Like

nvm i just needed to make it looped at animation editor.
Thank you all for replies :heart:

2 Likes

If statments only check once. Meaning if the value was false at the start of the game, and it changed to true it wouldn’t detect that it changed to true. You can use .Changed with the value object to check whenever the Value has changed.

script.Parent BoolValue.Changed:Connect(function()      
     if script.Parent.BoolValue.Value == true then
	    Track.Looped = true
	    Track:Play()
	end
	
	
	if script.Parent.BoolValue.Value == false then
		Track.Looped = false
		Track:Stop()
	end
end)
1 Like