:Stop() Not Working, I Need Help [Solved!]

Hi! I seem to have this problem where i have a local to server event to play an animation, but the :Stop() isnt working for the animation, however, the :Play() is. I also just wanna say that ive tried switching the :Play() And :Stop() to a local script (which didnt work) but i still need to event to run some other code anyways, after a bit of debugging I realized that the problem was the :Stop() (As mentioned before), not the server event or anything else (I Hope)

Provide an overview of:

  • What does the code do and what are you not satisfied with?
    my code is a block script and the animation is starting but not ending with :Stop()
  • What potential improvements have you considered?
    Ive tried switching the :Play() and :Stop() to a local script
  • How (specifically) do you want to improve the code?
    Simple just make the :Stop work

The Local Script:

local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local blockevent = script.Parent.BlockEvent
local unblockevent = script.Parent.UnBlockEvent


uis.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.F then
			blockevent:FireServer()
		end
end)

uis.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.F then
		unblockevent:FireServer()
	end
end)

The Server Script:

llocal uis = game:GetService("UserInputService")
local blockevent = script.BlockEvent
local unblockevent = script.UnBlockEvent
local blockanim = script.BlockAnim

blockevent.OnServerEvent:Connect(function(player)
	
		local humanoid = player.Character.Humanoid
	    local animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(blockanim)
		animationTrack:Play()
		
end)


unblockevent.OnServerEvent:Connect(function(player)

	local humanoid = player.Character.Humanoid
	local animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(blockanim)
	animationTrack:Stop()

end)
1 Like

Woops! I just realized a fix I can use, and it worked! Really sorry for making this post for nothing, if someone could give me a few instructions on how to close the post and mark the solution? (Thanks!)

Back to the solution:
when unblocking (all being said is from server script btw) it re-defines the animationtrack, so the game (probably to save power) since it sees that the animation isnt playing, doesnt even bother to end it, additionally, even if I didn’t re-define it, the animationtrack on the block event was local.

My fix was to delete everything but the animationTrack:Stop() in the unblock event and define animationTrack as a global variable in blockevent, so the code would look like this

local uis = game:GetService("UserInputService")
local blockevent = script.BlockEvent
local unblockevent = script.UnBlockEvent
local blockanim = script.BlockAnim
blockevent.OnServerEvent:Connect(function(player)
	local humanoid = player.Character.Humanoid
	animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(blockanim)
	animationTrack:Play()	
end)
unblockevent.OnServerEvent:Connect(function(player)
	animationTrack:Stop()
end)

Ya can switch the topic to #help-and-feedback:scripting-support and mark your post as the solution

1 Like

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