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

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

Asked by 2 years ago

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 — 2y
0
anchor their humanoid root part BearGamesZ 4 — 2y

2 answers

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
2 years 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
        local Char = plr.CharacterAdded:wait()
        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
        local Char = plr.CharacterAdded:wait()
        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!

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


Plrs.PlayerAdded:Connect(function(player)

    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

Answer this question