Disable Controls without losing MoveVector

How would I disable player controls without losing the move vector?

I tried CAS and reassigning keys but it disconnects the movevector from players controls as well

Change walkspeed and jumppower to 0

Im not tryna disable those to avoid cases where walkspeed and jumpower arent the default values


local Player = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
local Humanoid = Player:WaitForChild('Humanoid')

local ws = Humanoid.WalkSpeed
local jh = Humanoid.JumpHeight
 
Humanoid.JumpHeight = 0
Humanoid.WalkSpeed = 0 


wait(3)

Humanoid.JumpHeight = jh
Humanoid.WalkSpeed = ws

this will save the current walkspeed and jumpheight value to reapply when you want to enable controls again

and what if the players speed changes from an event during disabled controls using this method

Hook into the Changed event, update the variable, and set their speed back to 0. It’s instant and nobody will be able to move during the brief period that their speed is above 0.

1 Like
local playerSpeeds = {}

local isDisabled = false


local character = game.Players.LocalPlayer.CharacterAdded:Wait()
local Humanoid = character:WaitForChild('Humanoid')


local function newHumanoid(humanoid)
	
	task.wait()
	
	if humanoid.WalkSpeed > 0 then
		playerSpeeds.WalkSpeed = humanoid.WalkSpeed
	end
	
	if humanoid.JumpHeight > 0 then
		playerSpeeds.JumpHeight = humanoid.JumpHeight
	end 
	
	local changedConnection 
	local humanoidDestroy
	
	local function changedProperty(changeProperty)
		if changeProperty == "WalkSpeed" and humanoid.WalkSpeed > 0  then
			playerSpeeds.WalkSpeed = humanoid.WalkSpeed
		elseif changeProperty == "JumpHeight" and humanoid.JumpHeight > 0  then
			playerSpeeds.JumpHeight = humanoid.JumpHeight
		end
		if isDisabled == true then
			humanoid.JumpHeight = 0 
			humanoid.WalkSpeed = 0 
		end
	end
	
	local function humanoidCheck()
		if not humanoid:IsDescendantOf(game.Workspace) then
			changedConnection:Disconnect()
			humanoidDestroy:Disconnect()
		end
	end
	
	changedConnection = humanoid.Changed:connect(changedProperty)
	
	humanoidDestroy = humanoid.AncestryChanged:connect(humanoidCheck)
	
end

local function disableControls()
	if isDisabled == false then
		isDisabled = true
		if Humanoid then

			Humanoid.WalkSpeed = 0
			Humanoid.JumpHeight = 0

		end
	end
end

local function enableControls()
	if Humanoid then
		isDisabled = false
		Humanoid.WalkSpeed = playerSpeeds.WalkSpeed
		Humanoid.JumpHeight = playerSpeeds.JumpHeight
	end
end

newHumanoid(Humanoid)


game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
	character = char
	Humanoid = character:WaitForChild('Humanoid')
	newHumanoid(Humanoid)
end)

Haven’t tested but should work