How to disable x/y player movement?

What script can cancel the player walking movement? Like, in a way their only option is to jump.
But also in a way I can turn it on and off with a simple function.
Is setting the player walkspeed to 0 a good idea?

Quick edit: added the scripting and help extra tags

Setting the player’s WalkSpeed to 0 is a straightforward way to stop movement, but it might not be the most flexible or efficient method. Instead, you can use the ContextActionService to disable player movement, which allows for more control and can be easily toggled on and off.

Example:

local ContextActionService = game:GetService("ContextActionService")
local ACTION = "freezeMovement"

-- Disable movement
local function disableMovement()
	ContextActionService:BindAction(
		ACTION,
		function() return Enum.ContextActionResult.Sink end,
		false,
		unpack(Enum.PlayerActions:GetEnumItems())
	)
end

-- Enable movement
local function enableMovement()
	ContextActionService:UnbindAction(ACTION)
end

-- Example usage
disableMovement() -- Call this to disable movement
-- enableMovement() -- Call this to enable movement

1 Like

Hey, thanks! Only problem is that it also cancels jumping, which I need. (I’m trying to make the player character like Flappy Bird)

A Flappy Bird character should:

  1. Not be able to move around
  2. Be able to infinitly jump with a tiny cooldown
  3. Face a certain position preferably (right/left)

I was planning to first make the player freeze, then a new topic for the others

But can you help me allow jumping even even when freezed?

My bad, I forgot to exclude the jumping, here’s how you can do it:

local ContextActionService = game:GetService("ContextActionService")
local ACTION = "freezeMovement"

local Disable = {
	Enum.PlayerActions.CharacterLeft,
	Enum.PlayerActions.CharacterRight,
	Enum.PlayerActions.CharacterForward,
	Enum.PlayerActions.CharacterBackward,
}


-- Disable movement
local function disableMovement()
	ContextActionService:BindAction(
		ACTION,
		function() 
			return Enum.ContextActionResult.Sink
		end,
		false,
		unpack(Disable)
	)
end

-- Enable movement
local function enableMovement()
	ContextActionService:UnbindAction(ACTION)
end

-- Example usage
disableMovement() -- Call this to disable movement
-- enableMovement() -- Call this to enable movement
1 Like

Wow thanks really! I’m new here :baby: I did not knew how to do that. My plan was to now make a new topic for the infinite jump, if you helped me there as well I would love it :heart:

1 Like

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