Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I disable keyboard movement?

Asked by
LawlR 182
5 years ago
Edited 5 years ago

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.

0
u could anchor the player tacotown2 119 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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 
0
Thanks man. LawlR 182 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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.

Answer this question