Problem on scripting crouch!

I tried to make crouch animation but it doesnt functions. I did debugging but it printed all of them. Can someone take a look?

game.ReplicatedStorage.Crouch.OnServerEvent:Connect(function(player, began)
	local animation = script:FindFirstChild("Animation")
	print("Replicated Storage")
	local character = player.Character
	local humanim = character.Humanoid
	print("Humanoid")
	local anim = humanim:LoadAnimation(animation)
	print("Animation")
	if began == true then
		anim:Play()
		print("Played")
	else
		anim:Stop()
		print("Stopped")
	end
end)
1 Like

It could be a problem with the animation itself. Whenever I animate it has very similar problems, so maybe try tutorials on animating online.

1 Like

Make sure the server event is being triggered correctly. Double-check that the client-side code is correctly calling the server event and passing the “began” parameter.

Confirm that the “character” variable is not nil. If the player’s character has not loaded yet or has been destroyed, it could cause issues. You can add a check for if character then before accessing the “Humanoid” property.

1 Like

youre loading the animation each time you fire the remote.

for players joining, add a table of the animations
example: loaded_crouch_animations[player]:Play()
use the code like you had to set the table entry loaded_crouch_animations[player] = anim
image

1 Like

wouldn’t it be easier to just load the animation on a local script since it will still replicate to the server rather than firing an event and making the server load it?

and another potential problem is that you’re not loading the animation directly through the animator as recommended by the docs

1 Like

Humanoid.Animator yes this is better

1 Like