Animation behaves weridly

script:


local animator = player.Character.Humanoid:WaitForChild("Animator")
local anim = animator:LoadAnimation(player.Character.Animation)

local function onUpdate()
	if player.Character and player.Character:FindFirstChild("Humanoid") then
		

		if down == true then

			
			anim:Play()
	anim.Looped = true



		end
	end
end

i want the animation to play when I hold it, however, it becomes stuck at the start if I hold it, but plays normally when i let go???

1 Like

It’s because the script is replaying the animation every time you call the update function. You haven’t shown us half the code though so we can’t help.

1 Like

well the function fires every renderstep and down is just mousedown as a variable
how could i stop it from playing in the beginning every time?

Why do you need to keep replaying it? Isn’t the whole point of looped that you won’t have to replay it?

yes but i have3 to stop it at some point, i am trying to make it so the animation plays when the down is true and stops when it is false

	if down == true then
		
			--player.Character.HumanoidRootPart.ANG.AngularVelocity = Vector3.new(0,0,math.rad(number/2))
			
			anim:Play()
			anim.Looped = true

		else 
		anim:Stop()

		end

however its just stuck so the cde in the first post is me trying to debug it

1 Like

Then instead of running an update every frame, start the animation when they begin to hold their mouse down, and end it when they lift their mouse.

isn’t that what the current code does? (sorry ive never delt with animations a lot)

No, it checks every single frame that their mouse is down. You do realize there are events to detect when their mouse is down right?

More code would be helpful, because your problem is simple to fix.

well yeah, its check for the mouse holding
heres the rest i think is revelent

mouse.Button1Down:Connect(function()
	down = true

end)
mouse.Button1Up:Connect(function()
	down = false

end)
RunService:BindToRenderStep("Control", Enum.RenderPriority.Input.Value, onUpdate)

Yeah, in those two functions, start the animation, and then end it.

Code:

mouse.Button1Down:Connect(function()
	anim:Play()
	anim.Looped = true
end)

mouse.Button1Up:Connect(function()
	anim:Stop()
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.