Barrage animation won't return to idle animation when E is released

Title is self explanatory. Server script:

RS.Barrage.OnServerEvent:Connect(function(player, stand, barraging) --stand is the stand model, barraging is the bool
	local weld = stand.PrimaryPart.Controller
	local stand_anim = stand.AnimationController:LoadAnimation(script.Barrage)
	stand_anim:Stop()
	if barraging == true then
		print(player.Name.."'s stand "..stand.Name.." is barraging")
		TS:Create(weld, TweenInfo.new(0.4), {['C0'] = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame), ['C1'] = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame * CFrame.new(0,1.5,-2))}):Play()
		stand_anim.Looped = true
		stand_anim:Play()
	else
		print(player.Name.."'s stand "..stand.Name.." has stopped barraging")
		stand.AnimationController:LoadAnimation(script.Barrage):Stop()
		TS:Create(weld, TweenInfo.new(0.4), {['C0'] = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame), ['C1'] = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame * CFrame.new(-2.5, 1, 2))}):Play()
	end
end)

Local script:

...
	if active then
			if input.KeyCode == Enum.KeyCode.E then
				if barrage_db == false then
					barraging = true
					barrage:FireServer(stand, true)
					task.wait(barrage_cd)
					barrage_db = false
					if barrage_db == false then
						barrage_db = true
						task.wait(barrage_cd)
						barrage_db = false
					end
				end
			end
		end
	end
end)

UIS.InputEnded:Connect(function(input, typing)
	if typing then return end
	if active then
		if input.KeyCode == Enum.KeyCode.E then
			if barraging == true and barrage_db == false then
				barraging = false
				barrage_db = true
				barrage:FireServer(player.Character:FindFirstChildWhichIsA("Model"), false)
				task.wait(barrage_cd)
				barrage_db = true
			end
		end
	end
end)
1 Like

why do you write the entire

‘stand.AnimationController:LoadAnimation(script.Barrage)’

before putting :Stop()?

I’m pretty bad at scripting but maybe just putting stand_anim:Stop() for the long line of code would fix your problem.

I did that, and even then it doesn’t stop.

This happens because you load the Barrage Animation every single time you fire the event, and it returns a new animation, not the one that was used prior. The simplest way to get around this is to save these animations in a table for each stand character model.

I hope this helps!

How could I do this? Could you provide some code samples or pseudocode?

When you run stand.AnimationController:LoadAnimation(script.Barrage):Stop(), :LoadAnimation() actually returns an AnimationTrack object which you then use the :Stop() method on.

save the AnimaionTrack somewhere in a variable which you then use for later
e.g

local anim = Animator:LoadAnimation(Animation)
anim:Play()
anim:Stop()

I don’t think this will work, because my system uses a remote event that passes in the stand model, and I can’t load the animation outside of the remote event without the stand model.

Anyone have any ideas for solutions?

Hello im making a jojo game and have a good experience with making stands.

When an animation is looped and want to be stopped you need to type this

for i,Anims in pairs (stand.AnimationController:GetPlayingAnimationTracks() do
if anims.Name == "YourAnimationName" then
Anims:Stop()
end
end
2 Likes