Disallow movement/input for all players then re allowing it

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.

1 Like

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.

Cheers, I’ll try this out. 30chars

Surely this would put all players at the exact some position? That wouldn’t be very good for the game i’m planning.

Setting the HumanoidRootPart of a player to Anchored = true should disable all movement until it’s disabled.

Hope this helps,
-Tom :slight_smile:

2 Likes

The position can be set for each player. They don’t all need to be the same. What Thomas suggested will also work.

Well actually, as @ernakou mentioned, the position in the BodyPosition would have to match the player’s torso position.

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
1 Like

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.

1 Like

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.

I generally use the ContextActionService method, as suggested by @megukoo, but it’s totally up to you which method you use, as long as it works!

2 Likes

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.

You could wrap this in a function:

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)
1 Like

Can’t use an if statement in this for some reason. I just want the script to run if a string value has a certain value.

So you’d need to use the .Changed event of ValueBases, and run the function if the Value matches what you need.

Oh yes! I forgot that was even a thing. Thanks!

1 Like

I’d definitely give this a try.