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

How to disable controls ( for a cutscene ) ?

Asked by
bloxxyz 274 Moderation Voter
9 years ago

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!

2
A good way to do this is to make the player's walkspeed zero for an amount of time. HungryJaffer 1246 — 9y
1
Thank you, but some controls are still acknowledged with this method. Still useful, though. bloxxyz 274 — 9y

3 answers

Log in to vote
8
Answered by
woodengop 1134 Moderation Voter
9 years ago

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()

2
Thank you! This is very helpful. bloxxyz 274 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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.


Final Product

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
0
Thank you so much! I know I am late to this, but does this also work in a script outside of StarterPlayer inside of StarterPlayerScripts? baldi92102 2 — 4y
0
Do you know how to enable it again because when I try doing MasterControl:Enable() it is not working. baldi92102 2 — 4y

Answer this question