How do I disable players movement

When I use the code below in a script, when the character resets the player becomes stuck. How can I fix this? Any other to disable player movement?

local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
controls:Disable()
controls:Enable()
1 Like

The easiest way to do this would be through StarterPlayer. Why don’t you just set StartPlayer.CharacterWalkSpeed to 0, and the same with jump power? You don’t need a script to do this.

Way #2
You can also change the walkspeed and jump power of the humanoid (through script)

game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 0
game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").JumpPower= 0
4 Likes

If you are familiar with ModuleScripts, one I always include in my games is the following:

-- ModuleScript
local PlayerMovement = {}

function PlayerMovement:Movement(Player, move)
	
	local ContextActionService = game:GetService("ContextActionService")
	local FREEZE_ACTION = "freezeMovement"
	
	if move == false then
		
		ContextActionService:BindAction(
		    FREEZE_ACTION,
		    function()
		        return Enum.ContextActionResult.Sink
		    end,
		    false,
		    unpack(Enum.PlayerActions:GetEnumItems())
		)
	
	elseif move == true then
	
		ContextActionService:UnbindAction(FREEZE_ACTION)
		
	end
	
end

return PlayerMovement
-- Local Script
local PlayerMovement = require(PlayerMovement)

PlayerMovement:Movement(game.Players.LocalPlayer, false) -- stop movement
PlayerMovement:Movement(game.Players.LocalPlayer, true) -- allow movement

Now, keep in mind. When you stop movement, it wont allow the Player to:

  • User WASD or Arrow Keys
  • Jump
  • Any kind of movement-related input

Original Source:

9 Likes

Here’s another post that does just about the same thing, it also disables jumping:

How can I disable the player in an efficient way? Other methods have problems - Help and Feedback / Scripting Support - DevForum | Roblox

here’s how I would code it:

-- this is a local script
local ContextActionService = game:GetService("ContextActionService")

local function sink()
	return Enum.ContextActionResult.Sink
end

-- Freeze player (have this part run when you want the character to freeze)
-- make sure the player and character have loaded already
ContextActionService:BindAction(
	"Freeze", -- action name (this is used to unbind action)
	sink, -- function that is called when action activates
	false, -- if true creates a touch button for mobile
	unpack(Enum.PlayerActions:GetEnumItems()) -- list of actions (all player actions)
)

Then if you want to unfreeze the player:

-- code to unfreeze player
ContextActionService:UnbindAction("Freeze")

Hope this helps!

5 Likes

To do this with 1 line of code:

player.Character:WaitForChild("Humanoid").PlatformStand = true

to Unfreeze:

player.Character:WaitForChild("Humanoid").PlatformStand = false
1 Like

This code does not seem to freeze players on mobile, right? What can I do to freeze player’s on other devices too?

Edit: It’s been two years since last reply LOL

Hello! I happen to see this as I am hardly active on the forum like before.

In regards to your question:

Referring back to earlier in the post:

This method should work on any device, as it is not keybind-related or device-specific. The function actually unbinds the Core script’s built-in movement scripts. Therefore, the player cannot move until they are restored (which is done when you tell the module to allow movement again).

1 Like

doesn’t seem to work on mobile for me, did you check it out?