Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I disable keyboard movement?

I want the player to not be able to move using their keyboard while doing a cutscene. During this cutscene, the player will forced to walk to a specific point, so that means I can't just anchor the root part or set WalkSpeed to 0.

I tried to do this using UnbindContextActions() from the keyboard control module, however when doing this the character keeps on moving where ever it was moving before calling the function. Another problem is that when you call BindContextActions() afterwards, it throws a bunch of errors and immobilises the player.

1 comment

0

u could anchor the player

2 answers

✓ Accepted answer

I recently did cutscenes and I used the control module, this would go in a local script

local ControlModule = require(game.Players.LocalPlayer:WaitForChild('PlayerScripts'):WaitForChild('PlayerModule'):WaitForChild('ControlModule'))

ControlModule:Disable() -- Stops movement
ControlModule:Enable() -- Allows movement 

1 comment

0

Thanks man.

A pretty funky solution to this is to use high priority ContextActionService. This can temporarily override WASD controls with a function serving no purpose other than to eat input.

You can do this as follows (in a LocalScript):

local CAS = game:GetService("ContextActionService")

function SinkFunction() end

function EnableWASD()
	CAS:UnbindAction("Disable")
	CAS:UnbindAction("Disable2")
	CAS:UnbindAction("Disable3")
	CAS:UnbindAction("Disable4")
end

function DisableWASD()
	CAS:BindActionAtPriority("Disable", SinkFunction, false, 9999999, Enum.KeyCode.W)
	CAS:BindActionAtPriority("Disable2", SinkFunction, false, 9999999, Enum.KeyCode.A)
	CAS:BindActionAtPriority("Disable3", SinkFunction, false, 9999999, Enum.KeyCode.S)
	CAS:BindActionAtPriority("Disable4", SinkFunction, false, 9999999, Enum.KeyCode.D)
end

-- EnableWASD()
-- DisableWASD()

You can call EnableWASD() and DisableWASD() to enable or disable WASD input.

This discussion is preserved as it was. New answers, comments, and votes are closed.