Animation not stopping, causing other animations to not play

I have 2 animations for my ability. One is a holding animation, and the other is a throwing animation.
The holding animation plays when I press the key, but doesn’t stop, and the throwing animation doesn’t play because the holding wont stop.

I use variables to load the animations to the animator and then :Play() and :Stop(), however Stop seems to be failing.

	local HoldAnimation = Player.Character:WaitForChild("Humanoid").Animator:LoadAnimation(game.ServerStorage.Animations.FireballHold)
	local ThrowAnimation = Player.Character:WaitForChild("Humanoid").Animator:LoadAnimation(game.ServerStorage.Animations.FireballThrow)

-- random script

HoldAnimation:Play() -- plays fine

-- more random script

HoldAnimation:Stop() -- doesnt stop
ThrowAnimation:Play() -- doesnt play

I’ve also tried using loops to stop all animation tracks, but those don’t work either.

1 Like

Just check if the animation is or isnt playing.

local HoldAnimation = Player.Character:WaitForChild("Humanoid").Animator:LoadAnimation(game.ServerStorage.Animations.FireballHold)
	local ThrowAnimation = Player.Character:WaitForChild("Humanoid").Animator:LoadAnimation(game.ServerStorage.Animations.FireballThrow)

-- random script

HoldAnimation:Play() -- plays fine

-- more random script

if HoldAnimation.IsPlaying then
    HoldAnimation:Stop()
end

ThrowAnimation:Play() -- doesnt play

Also make sure that you are playing and loading the HoldAnimation in this script only (i believe)

1 Like

It still isn’t stopping… and the throw animation isnt playing either

1 Like

is this the full script? if not may i see the full script?

1 Like

it’s basically the full script since nothing interferes with animations

i had that problem before i fixed it by changing the animation priority to action

I already have the priority set to action

maybe try loading the animation to the Animator instead of the humanoid

1 Like

It already does load to the animator, I just changed it before posting the full script to see if it would work without Animator

oh on the script you sent it doesn’t show

yeah i changed it before posting the full script to see if it would work as just humanoid and forgot to change it back before sending the script

turns out i forgot to change the animation id of the throwing animation, so it was the same as the holding animation…

however the holding animation still isn’t stopping

1 Like

Could it be because the animation is looped? i’ve never had this issue with looped animations before but you never know
@dudezwithattitudez

Im not really sure about any other solution, but it seems like you are grabbing the character two times in the old script …

This is the new script I have written

local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local Debris = game:GetService("Debris")

Event.OnServerEvent:Connect(function(Player, Type, Mouse)
	local Char = Player.Character
	local Humanoid = Char:WaitForChild("Humanoid")
	local HRP = Char.HumanoidRootPart
	
	local HoldAnimation = Humanoid.Animator:LoadAnimation(game.ServerStorage.Animations.FireballHold)
	local ThrowAnimation = Humanoid.Animator:LoadAnimation(game.ServerStorage.Animations.FireballThrow)
	
	if Type == "start" then
		HoldAnimation:Play()
		local Fireball = game.ServerStorage.Fireball:Clone()
		Fireball.CFrame = HRP.CFrame * CFrame.new(0,0,-3)
		Fireball.Parent = Char
		Fireball.Anchored = true
		local Weld = Instance.new("WeldConstraint")
		Weld.Parent = Fireball
		Weld.Part0 = Fireball
		Weld.Part1 = HRP
		Fireball.Anchored = false

	elseif Type == "throw" then
		if HoldAnimation.IsPlaying then
			HoldAnimation:Stop(0)
			ThrowAnimation:Play()
		end
		local Fireball = Char:WaitForChild("Fireball")
		--[[local Fireball = game.ServerStorage.Fireball:Clone()
		Fireball.CFrame = HRP.CFrame * CFrame.new(0,0,-3)
		Fireball.Parent = workspace]]
		
		if Fireball:FindFirstChild("WeldConstraint") then
			Fireball:FindFirstChild("WeldConstraint"):Destroy()
		end

		local BV = Instance.new("BodyVelocity", Fireball)
		BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		BV.P = 10000000
		BV.Velocity = CFrame.new(Fireball.Position, Mouse).LookVector * 100

		Debris:AddItem(Fireball,5)

		Fireball.Touched:Connect(function(Touched)
			if Touched:IsDescendantOf(Char) then return end
			local CF = CFrame.new(Touched.Parent.PrimaryPart.Position + Vector3.new(0,2,0),Player.Character.HumanoidRootPart.Position)

			local y = Instance.new("BodyVelocity")
			y.maxForce = Vector3.new(-10000, 0, 0)
			y.Parent = Touched
			y.velocity = CF.LookVector * 50

			game:GetService("Debris"):AddItem(y,.5)

			for _,v in pairs(Fireball:GetDescendants()) do
				if v:IsA("PointLight") or v:IsA("Trail") then

					v.Enabled = false
				elseif v:IsA("ParticleEmitter") then
					v:Destroy()
				end
			end
			wait(1)
			Fireball:Destroy()
			ThrowAnimation:Stop()

			if Touched.Parent:FindFirstChild("Humanoid") then
				Touched.Parent:FindFirstChild("Humanoid"):TakeDamage(30)

				wait(0.5)
				Touched.Parent:WaitForChild("Ragdoll").Value = true
				wait(4)
				Touched.Parent:WaitForChild("Ragdoll").Value = false
			end
		end)
	end
end)

(i just edited the extra character variable out)

yeah I have to get the character twice because if I only get it once it’s not a variable in the “throw” section, as it doesn’t carry over an “elseif” statement

Your script doesn’t load the animation or create the fireball at all.

I tried the part of the script you used to stop the animation, and it didn’t stop it.
I added print statements for if the animation was still playing and when it gets stopped, nothing printed.

image

@dudezwithattitudez
I added print statements after each line and it printed stopped hold anim after the HoldAnimation:Stop() line but it didn’t stop

So, I have found a workaround for this I think.

I have created a brand new script, just tested it and its working fine. I just cant seem to figure out the mouse problem.

local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local Debris = game:GetService("Debris")

local animations = script:WaitForChild("Animations")

local Fireball
local Weld

local hold
local throw

local strstring = "start"
local endstring = "end"

Event.OnServerEvent:Connect(function(player, str)
	local chr = player.Character or player.CharacterAdded:Wait()
	local hum = chr:WaitForChild("Humanoid")

	local rootpart = chr:WaitForChild("HumanoidRootPart")
	local holdinghand = chr:WaitForChild("Left Arm")

	hold = hum.Animator:LoadAnimation(animations:WaitForChild("FireballHold"))
	throw = hum.Animator:LoadAnimation(animations:WaitForChild("FireballThrow"))

	if str == strstring and not hold.IsPlaying then
		print("play")
		hold:Play(0)
		Fireball = game:GetService("ServerStorage"):WaitForChild("Fireball"):Clone()
		Fireball.Parent = workspace
		Fireball.CFrame = holdinghand.CFrame * CFrame.new(0,-1,1)
		Fireball.Parent = chr
		Weld = Instance.new("WeldConstraint", Fireball)
		Weld.Part0 = Fireball
		Weld.Part1 = holdinghand
		
	end
end)

Event.OnServerEvent:Connect(function(player, str, mouse)
	local chr = player.Character or player.CharacterAdded:Wait()
	local hum = chr:WaitForChild("Humanoid")

	local rootpart = chr:WaitForChild("HumanoidRootPart")
	local holdinghand = chr:WaitForChild("Left Arm")

	if str == endstring and  hold.IsPlaying then
		print("stop")
		hold:Stop()
		throw:Play()
		throw:AdjustSpeed(2)
		
		Weld:Destroy()
		local BV = Instance.new("BodyVelocity", Fireball)
		BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		BV.P = 10000000
		BV.Velocity = mouse.Hit.LookVector * 100

		Debris:AddItem(Fireball,5)
		Fireball.Touched:Connect(function(Touched)
			if Touched:IsDescendantOf(chr) then return end
			local CF = CFrame.new(Touched.Parent.PrimaryPart.Position + Vector3.new(0,2,0),rootpart.Position)

			local y = Instance.new("BodyVelocity")
			y.maxForce = Vector3.new(-10000, 0, 0)
			y.Parent = Touched
			y.velocity = CF.LookVector * 50

			game:GetService("Debris"):AddItem(y,.5)

			--for _,v in pairs(Fireball:GetDescendants()) do
			--	if v:IsA("PointLight") or v:IsA("Trail") then

			--		v.Enabled = false
			--	elseif v:IsA("ParticleEmitter") then
			--		v:Destroy()
			--		end
			--end
			wait(1)
			Fireball:Destroy()
			throw:Stop()

			if Touched.Parent:FindFirstChild("Humanoid") then
				Touched.Parent:FindFirstChild("Humanoid"):TakeDamage(30)

				--wait(0.5)
				--	Touched.Parent:WaitForChild("Ragdoll").Value = true
				--wait(4)
				--Touched.Parent:WaitForChild("Ragdoll").Value = false
			end
		end)
	end
end)

The issue in this is super weird. I do blame Roblox’s programming language for this problem. Anyways the problem, it won’t detect the string and if the holding animation is playing at the same time? I have no clue, but thats my take on it.

Down below is a client script that I used to test the ServerScript.

local p = game:GetService("Players").LocalPlayer
local mouse = p:GetMouse()

local r = game:GetService("ReplicatedStorage").RemoteEvent

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		r:FireServer("start")
	end
end)

game:GetService("UserInputService").InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		r:FireServer("end", mouse)
	end
end)

fixed this line:

	if str == endstring and  hold.IsPlaying then
		print("stop")
		hold:Stop()
		throw:Play()
		throw:AdjustSpeed(2)

original line:

	if str == endstring and  hold.IsPlaying then
		print("stop")
		hold:Stop(0)

thank you! i’ll try it out and let you know if it works

1 Like