Anmation isn't stopping

Hello, I am making a blocking system and while I was testing I saw that my animation didn’t stop, I also researched on the devforum but nothing is helping me. If anyone could know how to fix this I would appreciate it, there isn’t any error on the output by the way.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local BlockingRemote = ReplicatedStorage:WaitForChild("Blocking Remote")

BlockingRemote.OnServerEvent:Connect(function(Player, Blocking)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild("Humanoid")
	
	local blockValue = Character.Blocking
	
	local Attacking = Character.Attacking
	if Attacking.Value == true then return end
	Attacking.Value = true
	
	local Blocking = Humanoid:LoadAnimation(script.Animations.Blocking)
	
	if Blocking then
		
		Blocking:Play()
		
		blockValue.Value = true
		print("Started server blocking")
		
	else
		
		Blocking:Stop()
		
		Blocking.Value = false
		print("Stopped server blocking")
		
	end
end)```
1 Like

Open the animation in the animator studio and hit run, if it loops you probably forgot to disable the loop button it kinda looks like this :repeat:

1 Like

It still doesn’t work and I realized that it doesn’t print “Stopped server blocking” either.

1 Like

Are you using an script? or a local script

2 Likes

I’m using a server script, would using a client script change it though?

1 Like

I’m pretty sure the issue is that you set the animation for blocking equal to ‘Blocking’ which overrides the Blocking parameter. So just change the name of the variable for the loaded blocking animation

1 Like

You are creating the variable for “Blocking” each time you fire the remote hence why it doesn’t stop. Put
“local Blocking = Humanoid:LoadAnimation(script.Animations.Blocking)” above the OnServerEvent. Your if statement also doesn’t work because Blocking is never set to nil or false so the else wont work. You need to make your if statement as “if not Blocking.IsPlaying then” or “if not blockValue.Value then” instead of “if Blocking then” also in your else statement you mistake “Blocking” for “blockValue”

1 Like

Then how would I make a variable for the humanoid if the animation variable is above the OnServerEvent. About the other things, they were right. It actually prints now but the animation still doesn’t stop.

This is my code now by the way.

I ended up fixing it. For anyone that is having the same problem as me just use for i, v in pairs.
Here’s an example
imagen_2023-10-11_162026761

1 Like

Quick Tip, Animators are recommended for loading animations, as loading animations through humanoids is deprecated (Animator | Documentation - Roblox Creator Hub).

Thanks, it seems useful. I’ll check that out.

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