Animation Glitches After Loop

Problem
Playing an animation in a while true loop causes it to glitch when I break out of it

Solutions
Already tried stopping all animations with the GetAnimationTracks but it still kept playing

GIF
String Sim Glitch

Code

while true do				
	AnimationTracksTable['Weight_Action']:Play()
	wait(WaitTime)
end

Any help would be appreciated, thank you!

1 Like

Using while true do is not very good performance-wise, i believe you should use something such as while task.wait() do

What are you trying to achieve? Are you trying to make it so that the animation stops when you unequip the tool?

while true do shouldn’t have that big of a difference if not none compared to task.wait() from what I’ve been told its what’s inside the code that matters. I believe task.wait() just waits for the next frame until it starts.

–Edit: Granted you have some wait between the loops. Sorry its very late… or early.

I want the animation to completely stop when I turn Auto Click off but it seems to keep or wanting to keep going when I stop it

Ah okay, my apologies. Yes you are right, it does depend on what it is in. I didn’t think about that in the moment! Not to mention, you do have a wait() in the while true do loop.

How does Auto Click work in your game? Does it play an animation constantly if the tool is equipped or does it change WaitTime?

What I’ve been told, task.wait() is more performant. Just that.
while true do task.wait() end or while task.wait() do end, its essentially the same.

What I dont understand is this:

When you stop the animation it will start again due to the while loop which is playing it again:

while true do				
	AnimationTracksTable['Weight_Action']:Play()
	wait(WaitTime)
end

How long is WaitTime? where that variable comes from?

Once Auto Click is pressed, it starts a loop playing an animation with a “cooldown” between each iteration.

You should break that loop and stop the animation when Auto Click turned off

Well, are you able to show more of your script? From what I understand, while true do will make it keep continuing even though the variable is true or false. This could be the reason why it is bugging out.

@Ssandst0rm
@Dev_Peashie

I apologize, it does break out eventually, but after that, the animation starts spasming. Here is the full code to clarify things a bit more.

while LocalVariablesDataFolder:GetAttribute('AutoClick') do
	local WeightSpeedVariable = LocalMultipliersDataFolder:GetAttribute('Speed')
						
	AnimationTracksTable['Weight_Action']:Play()
	AnimationTracksTable['Weight_Action']:AdjustSpeed(tonumber(WeightSpeedVariable))
						
	wait(ReturnTick(LocalCooldownsDataFolder:GetAttribute('Weight')) - tick())
end

I get what you are doing. I would start by debugging printing those values in tables, and a warning to show when the loop stopped.

This literally never stops? or just takes more time to stop?

The loop isn’t the problem, when I break out of it the animation doesn’t want to stop. instead, it starts glitching even when I manually stop it.

Okay, yk what… you were right… I did forget to exit the loop. BUT it was from not changing the attribute on the folder LMAO I’m so sorry for the trouble.

2 Likes

I was about to modify your script to my needs and test it to see that bug, haha good you found the reason! :yum:

1 Like

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