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.
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
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.