How to stop the player when playing an animation

Hello, I want to stop the player when playing the coconut eating animation. I need to make the player unable to move forward or backward in any way. Thank you in advance.

My script

  • local tool = script.Parent
  • local anim =“Animation”)
  • anim.AnimationId = “
  • local track
  • tool.Activated:Connect(function()
  • track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
  • track.Priority = Enum.AnimationPriority.Action
  • track.Looped = false
  • track:Play()
  • end)


There is probably a better way to do this, but you would need to set both humanoid.JumpPower and humanoid.WalkSpeed values to 0. That would make the player unable to move. I would start detecting if the player is moving first though, if they aren’t moving then it would still function nonetheless.

(just a side note, do this if y’want.)

If you don’t want them to rotate at all while eating the coconut, you could set their AutoRotate feature off which is inside of the Humanoid in the character. When the animation stops playing, you can turn the autorotate feature back on so that the player can start rotating on their own again. I’m pretty sure you can check when an animation is done playing, I think it was AnimTrack.Ended or something like that?

1 Like

Thank you very much. You helped me a lot. I’m sorry but could you show an example of how to write this script. It’s quite difficult for me, I only know basic scripts.

1 Like

First, you probably want to store the initial walkspeed of the player as a variable.
local initialSpeed = Humanoid.Walkspeed

Use the method shown below to set the
Humanoid.WalkSpeed to 0.

And then, wait a couple seconds using task.wait()

Finally, set the player walkspeed to what it was originally: Humanoid.WalkSpeed = initialSpeed

Also, please edit the post and set the topic correctly to Help and Feedback - Scripting Support

1 Like

I will give you a recreation of your script and a few resources to maybe help you learn a little more about what I have talked about.

Here is the script:

local player = game:GetService("Players").LocalPlayer

local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local tool = script.Parent

local anims_table = {
	coco_anim = tool:WaitForChild("Animations").Animation

local current_Walk_speed = humanoid.WalkSpeed
humanoid.WalkSpeed = current_Walk_speed
local current_jump_Power = humanoid.JumpPower
humanoid.JumpPower = current_jump_Power

local can_Activate = true

local track = humanoid.Animator:LoadAnimation(anims_table.coco_anim)


	if player and can_Activate then
		can_Activate = false

		track.Priority = Enum.AnimationPriority.Action
		track.Looped = false

		if humanoid.MoveDirection.Magnitude > 0 or humanoid.MoveDirection.Magnitude <= 0 then
			humanoid.AutoRotate = false
			humanoid.WalkSpeed = 0
			humanoid.JumpPower = 0


		humanoid.AutoRotate = true
		humanoid.WalkSpeed = current_Walk_speed
		humanoid.JumpPower = current_jump_Power

		can_Activate = true

	return tool

I do recommend adding a FOLDER inside of your TOOL, which could be something to store your ANIMATIONS in instead of creating and destroying animations which could change how the game functions in FPS. I do have a picture of the setup just incase you don’t understand what i’m talking about. Also, add a TABLE into your script so you can store your animations into that table, that way you don’t have to create multiple variables and make the script look all messy and unorganized.

Thank you so match bro! I did it!

1 Like

Bro sorry, have a problem, can you drop picture pls. I create folder named “Animations”
but i have Infinite yield possible on 'Players.MaaXGaz20.Backpack.Coconut:WaitForChild(“Animations”)
What i need to do?

Looks like I was in a bit of a rush here, I apologize.

Here is how your tool setup should look like:

Screenshot 2023-03-03 130048

Also make sure to use a LocalScript for the code up above.
The picture should pretty much just explain it all.

1 Like

:heart: :+1: Bro thank you so much, appreciate your help

1 Like

Bro i have a bug. What i can do?

have you copy and pasted the original code or did you write it down

i do Copy paste bro. What i can do?