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
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!
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