How would I disable the controls through scripts. Any help is appreciated :D
In order to disable controls of a player, I have noticed that when a player joins the game, there is a script called ControlScript which is located in game.Players.(Any player).PlayerScripts.
So, in order to disable it, you should insert a local script into game.StarterPlayer.StarterPlayerScripts.
Since it activates once the player joins, you do not need to add a PlayerAdded event but simply say this:
So, here are two ways to do it:
Local script: (This script is to disable movement upon game entrance)
1 | local ControlScript = script.Parent.FindFirstChild( "ControlScript" ) |
2 |
3 | --Add your other lines of code before or after this and use the line below to deactivate movement |
4 | ControlScript.Disabled = true |
You can use either local script: Just for the player or for server script: To stop everyone at once
This example is for server script:
01 | --To stop everyone from moving and jumping |
02 |
03 | for I,players in pairs (game.Players:GetChildren()) do |
04 | --To stop |
05 | players.Character.Humanoid.JumpPower = 0 |
06 | players.Character.Humanoid.WalkSpeed = 0 |
07 |
08 | wait() |
09 |
10 | --To move again |
11 | players.Character.Humanoid.JumpPower = 50 |
12 | players.Character.Humanoid.WalkSpeed = 16 |
13 | end |
Local script: Place this into starter pack (If you want to load instantly when player joins)
1 | --To stop |
2 | script.Parent.Parent.Character.Humanoid.JumpPower = 0 |
3 | script.Parent.Parent.Character.Humanoid.WalkSpeed = 0 |
4 |
5 | wait() |
6 |
7 | --To move again |
8 | script.Parent.Parent.Character.Humanoid.JumpPower = 50 |
9 | script.Parent.Parent.Character.Humanoid.WalkSpeed = 16 |
The correct way to disable a user's controls is to go inside the players dev settings. You could go ahead and change the jumppower and walkspeed but that’d be temporary. Using the below script would be the most efficient way you can find.
SCRIPT(Workspace)
01 | game:GetService( 'Players' ).PlayerAdded:connect( function (plr) |
02 | plr.CharacterAdded:connect( function () |
03 | plr.DevComputerMovementMode = 'Scriptable' --Turns off controls |
04 | plr.DevTouchMovementMode = 'Scriptable' --Just in case the player is in a mobile device(You can use another function to find out the device type) |
05 | print ( 'Controls Off' ) |
06 | end ) |
07 | wait( 10 ) |
08 | plr.DevComputerMovementMode = 'UserChoice' --Turns back on |
09 | plr.DevTouchMovementMode = 'UserChoice' |
10 | print ( 'Back online' ) |
11 | end ) |
I hope this answers your question and helps you in whatever you are trying to do here.
My examples:
01 | --All players (good for server scripts) |
02 |
03 | --Stop moving |
04 | for i,players in pairs (game.Players:GetPlayers()) do |
05 | if players.Character then |
06 | if players.Character:FindFirstChild( "Humanoid" ) then |
07 | players.Character.Humanoid.WalkSpeed = 0 |
08 | players.Character.Humanoid.JumpPower = 0 |
09 | end |
10 | end |
11 |
12 | end |
13 |
14 |
15 | --Start moving |
I hope i could help you out with this