So I made a simple little rotate animation for a valve wheel and it runs smoothly in Roblox’s animation editor but once I play it with a script by doing
RotateValveAnimation:Play(0.5)
It seems to stutter a bit half way as it plays? Here’s some footage:
In Roblox’s animation editor:
In game
What could be causing this behavior? Here’s the setup:
(Model in Workspace)
The code inside said script where RotateValveAnimation:Play(0.5) is included in.
local info = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
local info2 = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
local alreadyTriggered = false
local Valve = script.Parent
local ValveClickDetector = script.Parent.ClickDetector
local RotatingPart = game.Workspace.RotatingPart1
local RotateValveAnimation = script.Parent.Parent.AnimationController.Animator:LoadAnimation(script.RotateAnimation)
local direction = 1
local maxPos = 2
local currentPos = 0
Valve.ClickDetector.MouseClick:Connect(function()
if alreadyTriggered == false then
alreadyTriggered = true
local goals = {
Orientation = RotatingPart.Orientation + Vector3.new(0, 90 * direction, 0)
}
local platformtween = game:GetService("TweenService"):Create(RotatingPart,info,goals)
RotateValveAnimation:Play(0.5)
print("went through")
ValveClickDetector.MaxActivationDistance = 0
wait(0.2)
platformtween:Play()
-- update currentPos in direction
currentPos += direction
-- if currentPos has reached either end
if currentPos == 0 or currentPos == maxPos then
-- invert direction
direction = -direction
end
platformtween.Completed:Wait()
ValveClickDetector.MaxActivationDistance = 12
alreadyTriggered = false
end
end)
Could there be something in my script interfering with the animation playing? I’ve looked up several threads on this but nothing really worked for me. I’d appreciate your help on this little issue!
No, the Tween is for something else within the script. I’m making a puzzle where you rotate some wooden plank platforms by turning each handwheel valve to align the platforms so that you can cross. When a valve is clicked on, the platform rotates using Tween, and the valve itself will play it’s own animation shortly after clicked as well.
How would I continue to go about this without doing major changes to the script as it already works as intended besides the little stutter?
Edit:
Just experimented something, I erased all the code and only kept RotateValveAnimation:Play(0.5) for after clicking the valve to see if the valve acted any different when the script runs it with these changes and nope, seems to be something wrong with the animation but what could it be if it plays fine in Roblox’s animation editor?
After a bit more of messing around and looking more into the problem, I’ve come to a conclusion that something is most likely causing the animation to reset shortly after playing, is there any possible causes for this? I’m sure now that it’s not the script affecting it because
Once again, is there any causes behind animations resetting?
This is probably because your animation is being played on the server. Playing it on the client instead should fix the issue.
The main issue is caused by replication lag. Roblox studio simulates it so you will experience this problem in studio and when connected on the server.
If this isn’t the problem, it is most likely your animation playing twice.
Turns out that the 0.5 from RotateValveAnimation:Play(0.5) was the cause of the issue. For some reason I thought that it was some sort of wait time of once the animation was done playing but no lol. I ended up removing it and adding in an actual `task.wait(0.5) right after making the animation play.