How to disable player movement (I did research, and I still can't figure it out)

I realize a topic similar to this has been created a million times, and I have looked at each one, but I can’t disable player controls. Here is my script:

	local playerScripts = plr:WaitForChild("PlayerScripts")
	local playerModule = playerScripts:WaitForChild("PlayerModule")
	local controlModule = require(playerModule)
	local controls = controlModule:GetControls()

Here is where I’m trying to get the controls. The error I’m getting is that there is infinite yield to get the PlayerScripts. How can I fix this?

1 Like

You could set the movespeed to 0.0000000000000001

playerscripts only can be used on client, not server i believe

Is there a reason you couldn’t just set JumpPower and WalkSpeed to 0? For example, if you’re making a cutscene where the player is moving and you don’t want there input to interrupt there cutscene, then you couldn’t do this, but in general usually you can just set WalkSpeed and JumpPower/JumpHeight to 0.

1 Like

This can be bypassed by changing your move settings, but it allows you to force a player to walk somewhere

playerscripts = game.Players.LocalPlayer:WaitForChild("PlayerScripts")
local wfc= game.WaitForChild
local controlmodule = require(wfc(wfc(playerscripts, "PlayerModule"), "ControlModule"))
wait(3)
controlmodule:Disable()
wait(3)
controlmodule:Enable()
1 Like

I guess I could do that, it just feels kinda cheaty, but if I cant find another solution soon, then I will do that.

Freeze em. That’s the most easiest way you can do it. Just freeze the character’s humanoidrootpart.

character.HumanoidRootPart.Anchored = true

Notes

  • You might need a RemoteEvent to toggle between freezing and unfreezing the player (if you’re using a local script)
4 Likes

Fair point. Because the client always has control of it’s WalkSpeed, JumpPower and if it’s anchored if you want to be extra secure try the following instead. This uses ContextActionService. I forget where I found this method but I’ve been using it for awhile without issue.

local CAS = game:GetService("ContextActionService")
local FREEZE = "freezeMovement"

CAS:BindAction(FREEZE, function() return Enum.ContextActionResult.Sink end, false, unpack(Enum.PlayerActions:GetEnumItems())) -- freeze
task.wait(4) -- however long you want the player to be frozen
CAS:UnbindAction(FREEZE) -- unfreeze
1 Like

I’m using a server script and I can only use CAS from a local script. Any other ideas?

Hi, you can disable player movement with only anchoring the HumanoidRootPart. That’s the easiest way and it works perfectly

I don’t think I can do that because I want to disable movement because I am animating the character. Could I still do that without disturbing the animation?

im not quite sure how to help you on this one, like what type of animation you want to make?
like a cutscene animation or an emote or what?

It is kind of an emote, but not exactly. It essentially functions the same way as an emote. I just want to stop the player so I can animate them doing an action.

i think, i don’t know but are you using a server script or a local script?
because it works for me using a local script

if you may, could i see the script?

is this what you wantedish?
animation.rbxm (3.9 KB)

You are still able to play your animations normally even if the HumanoidRootPart is anchored.
Do note that if your making an animation where the player walks from point A to point B that would require you teleport the HRP to the destination after your animation stops

Well a little cheeky way to do this is just anchoring the players HRP

i think there would be a problem if the player is in mid air

I been doing this since day 1, the only problem with this is that if the player is running and you anchor them, the animation for the running will still be slightly playing

I mean, you could just do a :FireClient as well to use CAS, but that might seem unnecessary honestly.

If this is on the server and you want to keep it on the server, the only real options you could explore here are JumpPower + Walkspeed editing, or anchoring the HumanoidRootPart. Both have fundamental flaws here and disadvantages which code hinder the progress of your animation, especially if it requires the user to walk somewhere.

I mean, you could just do a :FireClient as well to use CAS, but that might seem unnecessary honestly.

If this is on the server and you want to keep it on the server, the only real options you could explore here are JumpPower + Walkspeed editing, or anchoring the HumanoidRootPart. Both have fundamental flaws here and disadvantages which could hinder the progress of your animation, especially if it requires the user to walk somewhere.