What I want to achieve.
I want to make a script so the players during the game countdown cannot move. Then after the countdown the players can then move around.
The issue.
I have tried changing the players walkspeed but I cannot succeed in making a script that can change all the players walkspeed then change it again (repeat). So I would rather not use another walkspeed script, I even made a post on here but I never got a script that matched my description. So is there any other way I can make it so the players cannot move? There’s a game called Obby Run, and they have an interesting way of not allowing the players to move, the players seem to be floating and falling.
Solutions I have tried.
Again, I have tried the walkspeed script but I was never successful in doing that. I have also tried a script that makes a part cancollide = true then cancollide = false, but that just flung the player. I was thinking of using maybe the velocity property to try and recreate the mentioned Obby Run effect.
So if you have any idea with how I can disallow movement for players then allow it after a certain time that would be brilliant. I would prefer if a walkspeed script was not used because I’ve spent days trying to figure out how I can make a walkspeed script work how I want to but I just cant find anything on it, and It’s kind of demotivating me a bit.
Create a BodyPosition with the position matching the torso’s position and use Debris:AddItem which has a parameter to delete an instance after a certain amount of time. So the BodyPosition would freeze the player in place, and automatically get cleaned up after X seconds.
I had posted this on another thread, but wasn’t exactly what they were looking for. Seems like it’s the case for you though.
You can use ContextActionService to sink the input of regular movement keys and back. You could use this in conjunction with FireAllClients to tell all players to stop moving.
local ContextAction = game:GetService("ContextActionService")
function sinkInput()
return Enum.ContextActionResult.Sink
-- Sinks the key so that no action is taken.
-- Since this will be the most recent bind to the key, it takes priority over default movement.
end
-- Disables movement.
function disableMovement()
ContextAction:BindAction("DisableMovement", sinkInput, false,
Enum.KeyCode.W,
Enum.KeyCode.A,
Enum.KeyCode.S,
Enum.KeyCode.D
)
end
-- Unbinds our "disable movement" so that the default keybinds are activated.
function enableMovement()
ContextAction:UnbindAction("DisableMovement")
end
Sorry to @ you all and sorry for being a bit of a noob but how would I go about editing the humanoid or just all the players humanoid without use CharacterAdded or anything? @megukoo @k_ermeet @ernakou @ThomasMGardiner
for _, Player in next, game:GetService("Players"):GetPlayers() do
if not (Player.Character and Player.Character.Parent) then
continue
end
local Humanoid = Player.Character:FindFirstChildWhichIsA("Humanoid")
if not Humanoid then
continue
end
Humanoid.WalkSpeed = 0
-- or whatever you need to do
end
You need to loop through Players and only process when you find everything you need (Character, Humanoid, etc.)
continue is new in Luau, and allows you to skip the current iteration in a loop.
A small detail, but this method would still allow for character rotation and jumping. If you want all movement to stop, I suggest using the anchor method.
This seems to be working great! However, am I able to add an if function or something because I want to change the walkspeed again if a boolean value has a certain value, I just don’t want to reply on a wait function to run the second walkspeed change.
local function SetAllWalkSpeeds(Speed)
for _, Player in next, game:GetService("Players"):GetPlayers() do
if not (Player.Character and Player.Character.Parent) then
continue
end
local Humanoid = Player.Character:FindFirstChildWhichIsA("Humanoid")
if not Humanoid then
continue
end
Humanoid.WalkSpeed = Speed
-- or whatever you need to do
end
end
SetAllWalkSpeeds(0)
wait(10)
SetAllWalkSpeeds(16)