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.
local control = game:GetService("ControllerService"):GetChildren() for _, controller in pairs(control) do controller.Parent = nil end
This removes the player's control, but how do we return the control back? Easy, return the ControllerService back to it's place.
local EmptyTable = {} -- Create a table to store the values in function Remove() for _, controller in pairs(game:GetService("ControllerService"):GetChildren()) do controller.Parent = nil table.insert(EmptyTable, controller) end end function Go() for _, controller in pairs(EmptyTable) do controller.Parent = game:GetService("ControllerService") -- Put the controller back into ControllerService end EmptyTable = {} -- Remove the Array's values. end Remove() wait(5) -- wait 5 seconds then return the controls. 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.
--LocalScript local control = script.Parent:WaitForChild("ControllerScript") function Stop() control.Parent = nil end function Resume() control.Parent = script.Parent end Stop() wait(5) 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:
local MasterControl = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"):WaitForChild("ControlModule")) game:GetService('RunService').RenderStepped:connect(function() MasterControl:Disable() 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.
local MasterControl = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"):WaitForChild("ControlModule")) game:GetService('RunService').RenderStepped:connect(function() MasterControl:Disable() workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable workspace.CurrentCamera.CFrame = game.Players.LocalPlayer.Character:WaitForChild('HumanoidRootPart').CFrame * CFrame.new(0,1.5,0.1) end)