I'm working with camera manipulation, but that's not what I'm asking about today. I'm just wondering if there is a way to temporarily disable W A S D, Arrow keys, and space bar for a certain amount of seconds so my cutscene script is fool proof. I couldn't find any wiki articles and the Scripting Forum on ROBLOX was baffled.
If you guys can find a wiki article or know how yourselves, please tell me. Thank you very much!
Disabling Player Controls:
There are 2 ways in disabling player controls, First: do what Hungrayjaffer suggested, set the player's Walkspeed to zero, or disabled the controls by accessing the ControllerService
service.
1 | local control = game:GetService( "ControllerService" ):GetChildren() |
2 |
3 | for _, controller in pairs (control) do |
4 | controller.Parent = nil |
5 | end |
This removes the player's control, but how do we return the control back? Easy, return the ControllerService back to it's place.
01 | local EmptyTable = { } -- Create a table to store the values in |
02 |
03 | function Remove() |
04 | for _, controller in pairs (game:GetService( "ControllerService" ):GetChildren()) do |
05 | controller.Parent = nil |
06 | table.insert(EmptyTable, controller) |
07 | end |
08 | end |
09 |
10 | function Go() |
11 | for _, controller in pairs (EmptyTable) do |
12 | controller.Parent = game:GetService( "ControllerService" ) -- Put the controller back into ControllerService |
13 | end |
14 | EmptyTable = { } -- Remove the Array's values. |
15 | end |
16 |
17 | Remove() |
18 | wait( 5 ) -- wait 5 seconds then return the controls. |
19 | Go() |
I know TheContinentOfEurope answered but I found a much more simpler way: Using the ControllerScript in PlayerScripts! This is a local script inside of it, call the function "Stop" then do the function "Resume" to make the person stop then be able to control again.
01 | --LocalScript |
02 | local control = script.Parent:WaitForChild( "ControllerScript" ) |
03 | function Stop() |
04 | control.Parent = nil |
05 | end |
06 | function Resume() |
07 | control.Parent = script.Parent |
08 | end |
09 | Stop() |
10 | wait( 5 ) |
11 | Resume() |
Hope it helps!
The answer you are looking for is this: Roblox updated their control stuff to modules. Player > PlayerScripts > PlayerModule
Now if you want to disable movement, you'd have to use the disable method built into the ControlModule that's a child of PlayerModule. I suggest doing this in a loop due to the fact that not doing so is buggy and sometimes doesn't work. You would do so like this:
1 | local MasterControl = require(game.Players.LocalPlayer:WaitForChild( "PlayerScripts" ):WaitForChild( "PlayerModule" ):WaitForChild( "ControlModule" )) |
2 |
3 | game:GetService( 'RunService' ).RenderStepped:connect( function () |
4 | MasterControl:Disable() |
5 | end ) |
And then you'd renable it by using the Enable method instead of disable.
As for the camera, you'd just make it scriptable and cframe it where you want it.
1 | local MasterControl = require(game.Players.LocalPlayer:WaitForChild( "PlayerScripts" ):WaitForChild( "PlayerModule" ):WaitForChild( "ControlModule" )) |
2 |
3 | game:GetService( 'RunService' ).RenderStepped:connect( function () |
4 | MasterControl:Disable() |
5 | workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable |
6 | workspace.CurrentCamera.CFrame = game.Players.LocalPlayer.Character:WaitForChild( 'HumanoidRootPart' ).CFrame * CFrame.new( 0 , 1.5 , 0.1 ) |
7 | end ) |