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 6 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 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 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)

local ControlScript = script.Parent.FindFirstChild("ControlScript")

--Add your other lines of code before or after this and use the line below to deactivate movement
ControlScript.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:

--To stop everyone from moving and jumping

for I,players in pairs(game.Players:GetChildren()) do
--To stop
    players.Character.Humanoid.JumpPower = 0
    players.Character.Humanoid.WalkSpeed = 0

wait()

--To move again
    players.Character.Humanoid.JumpPower = 50
    players.Character.Humanoid.WalkSpeed = 16
end

Local script: Place this into starter pack (If you want to load instantly when player joins)

--To stop
    script.Parent.Parent.Character.Humanoid.JumpPower = 0
    script.Parent.Parent.Character.Humanoid.WalkSpeed = 0

wait()

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

game:GetService('Players').PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function()
    plr.DevComputerMovementMode = 'Scriptable' --Turns off controls
    plr.DevTouchMovementMode = 'Scriptable' --Just in case the player is in a mobile device(You can use another function to find out the device type)
    print('Controls Off')
    end)
    wait(10)
    plr.DevComputerMovementMode = 'UserChoice' --Turns back on
    plr.DevTouchMovementMode = 'UserChoice'
    print('Back online')
end)

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

Log in to vote
0
Answered by 6 years ago

My examples:

--All players (good for server scripts)

--Stop moving
for i,players in pairs(game.Players:GetPlayers()) do
if players.Character then
if players.Character:FindFirstChild("Humanoid") then
players.Character.Humanoid.WalkSpeed = 0
players.Character.Humanoid.JumpPower= 0
end
end

end


--Start moving
for i,players in pairs(game.Players:GetPlayers()) do
if players.Character then
if players.Character:FindFirstChild("Humanoid") then
players.Character.Humanoid.WalkSpeed = 16 
players.Character.Humanoid.JumpPower= 50 
end
end

end






--LocalPlayer (works only on LocalScripts)
--Stop moving
local plr = game.Players.LocalPlayer
repeat wait(.2) until plr.Character
local char = plr.Character
char:WaitForChild("Humanoid")
char.Humanoid.WalkSpeed = 0
char.Humanoid.JumpPower= 0


--Start moving
local plr = game.Players.LocalPlayer
repeat wait(.2) until plr.Character
local char = plr.Character
char:WaitForChild("Humanoid")
char.Humanoid.WalkSpeed = 16
char.Humanoid.JumpPower= 50

I hope i could help you out with this

Answer this question