Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Looped Animation still plays after using :Stop(), how do I fix this?

game.ReplicatedStorage.FruitRemotes.GomuGomu.Pistol.OnServerEvent:Connect(function(player, hit, fruit)
	local pistolAnim = character:WaitForChild("Humanoid"):LoadAnimation(game.ReplicatedStorage.Animations.GomuGomu.PistolAnim)
	pistolAnim:Play()

end)

game.ReplicatedStorage.FruitRemotes.GomuGomu.PistolAttack.OnServerEvent:Connect(function(player, hit, fruit)
	local oldAnimation = character.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.GomuGomu.PistolAnim)
	oldAnimation:Stop()

end)

The code used to work, but now it doesn't. Could it possibly be a bug?

8 comments

0

hmm ill look into it

0

Thanks!

0

It most likely only works once, try adding a loop to stop the music more than once..

0

I'm using Animations, but I'll give that a try

0

Didn't work. I even checked if it printed, and it did. This is sooo weird...

0

When you stop an animation, it will continue until it's animation track is over.

0

Well it worked last time, now it all of a sudden doesn't.

2 answers

I am not an expert, but you could try first to set the Looped animation to false and then to stop. This could might work. Else you could try to check if the Remote Event/Function get even fired. Check it with

game.ReplicatedStorage.FruitRemotes.GomuGomu.Pistol.OnServerEvent:Connect(function(player, hit, fruit)
    local pistolAnim = character:WaitForChild("Humanoid"):LoadAnimation(game.ReplicatedStorage.Animations.GomuGomu.PistolAnim)
    pistolAnim:Play()

end)

game.ReplicatedStorage.FruitRemotes.GomuGomu.PistolAttack.OnServerEvent:Connect(function(player, hit, fruit)
    local oldAnimation = character.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.GomuGomu.PistolAnim)
    print("TEST")
    oldAnimation:Stop()

end)

I Hope I could helped you a bit infront :-)

1 comment

0

The remote events do work, but the :Stop() doesn't work as if it was never there. I tried setting the Looped to false, but it only worked for specific areas

Its because you are loading the animation again. you can fix it by making the animation variable a global variable.

game.ReplicatedStorage.FruitRemotes.GomuGomu.Pistol.OnServerEvent:Connect(function(player, hit, fruit)
pistolAnim =character:WaitForChild("Humanoid"):LoadAnimation(game.ReplicatedStorage.Animations.GomuGomu.PistolAnim)
    pistolAnim:Play()

end)

game.ReplicatedStorage.FruitRemotes.GomuGomu.PistolAttack.OnServerEvent:Connect(function(player, hit, fruit)
    pistolAnim:Stop()

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.