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

How do I disable a characters controls (WASD and Space Bar)?

Asked by 7 years ago

How would I disable the controls through scripts. Any help is appreciated :D

0
change the characters speed to 0 and find a random model from toolbox lmao, bye bye greatneil80 2647 — 7y

3 answers

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

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:

1 Disable Roblox's default control script.

Local script: (This script is to disable movement upon game entrance)

1local 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
4ControlScript.Disabled = true

2 Set Player's JumpPower and Walkspeed to 0

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 
03for I,players in pairs(game.Players:GetChildren()) do
04--To stop
05    players.Character.Humanoid.JumpPower = 0
06    players.Character.Humanoid.WalkSpeed = 0
07 
08wait()
09 
10--To move again
11    players.Character.Humanoid.JumpPower = 50
12    players.Character.Humanoid.WalkSpeed = 16
13end

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 
5wait()
6 
7--To move again
8    script.Parent.Parent.Character.Humanoid.JumpPower = 50
9    script.Parent.Parent.Character.Humanoid.WalkSpeed = 16
Ad
Log in to vote
0
Answered by
FazNook 61
7 years ago
Edited 7 years ago

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)

01game: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')
11end)

I hope this answers your question and helps you in whatever you are trying to do here.

Log in to vote
0
Answered by 7 years ago

My examples:

01--All players (good for server scripts)
02 
03--Stop moving
04for i,players in pairs(game.Players:GetPlayers()) do
05if players.Character then
06if players.Character:FindFirstChild("Humanoid") then
07players.Character.Humanoid.WalkSpeed = 0
08players.Character.Humanoid.JumpPower= 0
09end
10end
11 
12end
13 
14 
15--Start moving
View all 47 lines...

I hope i could help you out with this

Answer this question