0

is there a way I can disable a players movements in a server script?

I have already defined the player as plr, I want it to disable the movements if a certain part is red, but when it turns green I want the players movements to be enabled again

0
Maybe you could anchor their humanoidrootpart or set walkspeed to 0? StayMarkus 0 — 1y
0
anchor their humanoid root part BearGamesZ 4 — 1y

0
TGazza 1336
1 year ago

Just a mock-up code (untested since I'm on my phone). But the Guts of this code should be what you want.

Combining Both comments from StayMarkus(WalkSpeed) and BearGamesZ(HumanoidRootPart.Anchored)

HumanoidRootPart.Anchored

local Players = game:GetService("Players")
local Freeze = false

while true do
for k,plr in pairs(Players:GetPlayers()) do
if(Char ~= nil) then
local HRP = Char:FindFirstChild("HumanoidRootPart")
if(Freeze == true) then
HRP.Anchored = true
else
HRP.Anchored = false
end
end

end

wait()
end


Humanod.WalkSpeed

local Players = game:GetService("Players")
local Freeze = false

while true do
for k,plr in pairs(Players:GetPlayers()) do
if(Char ~= nil) then
local Humanoid= Char:FindFirstChild("Humanoid")
if(Freeze == true) then
Humanoid.WalkSpeed= 0
else
Humanoid.WalkSpeed= 16
end
end

end

wait()
end


Both bit of code are untested but it should show you how to do this!. Hope this helps!

0
Edited 1 year ago

There's actually two ways and the first one might not work.

You could try this way by simply adding a server script in the ServerScriptService.

local SP = game:GetService("StarterPlayer")

SP.CharacterWalkSpeed = 0

-- And if you want, we can disable jumping too, but just delete this part if you don't.
SP.CharacterUseJumpPower = 0


OR

You can do it this way:

local Plrs = game:GetService("Players")

local char = workspace[player.Name]

-- Now we got the character, we can find the HumanoidRootPart.

local root = char:WaitForChild("HumanoidRootPart")

-- Anchoring the root part will stop the player from moving, or jumping.
root.Anchored == true
end)



I hope this helped! Mark as solution if it did :D