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

How do I prevent players from moving while in mid-air?

Asked by 8 years ago

The question title is pretty self-explanatory. Basically what I want to do is have the characters not be able to control their movement while their freefalling or in mid-air, to make stuff more realistic. But I'm not really sure how I would go about doing something like that, any suggestions?

NOTE: I'm not asking for a script, I'm asking for suggestions or methods or a breakdown.

Thanks.

0
If Fall animation is playing then do, something like that, idk. iNicklas 215 — 8y
0
'if then do' do you even know how to script unmiss 337 — 8y
0
I guess you could do magnitude of player to baseplate... or use a changed event and if jump goes true, remove their speed then use a wait and make the speed again alphawolvess 1784 — 8y
0
Like he said, try editing the speed. You could also disable their controls within Player>PlayerScripts (or whatever the name is, currently not in studio)/disable the ControlScript. unmiss 337 — 8y
0
Alpha, why only the baseplate? There may be parts the player is jumping on that are not the baseplate. And it would be highly ineffecient to check every single parts distance from the character DigitalVeer 1473 — 8y

3 answers

Log in to vote
1
Answered by 8 years ago

FreeFalling

What is important here: If you take a look at the events of a humanoid, you'll notice that there is a freeFalling event.

The key to understanding the freeFalling event is that the argument which is given by the event is the status of whether or not the player is actually freeFalling anymore. For example, let's make a local script to test this event out:

local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:wait()
local hum = chr:FindFirstChild("Humanoid")
local falling = false

    hum.FreeFalling:connect(function(isFalling)
        falling = isFalling
        if isFalling then
            while falling do
                print("Falling!")
                wait()
            end
        else
            print("Not Falling!")
        end
    end)

Now, if you want to make the character still, we obviously only have to put the humanoid WalkSpeed property to 0, which makes the player still, and if the character is not falling, then we just set the walkspeed back to normal.

local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:wait()
local hum = chr:FindFirstChild("Humanoid")
local falling = false

    hum.FreeFalling:connect(function(isFalling)
        falling = isFalling
        if isFalling then
            while falling do
                hum.WalkSpeed = 0;
                wait()
            end
        else
            hum.WalkSpeed = 16;
        end
    end)

Useful Links:

Humanoid: http://wiki.roblox.com/index.php?title=API:Class/Humanoid

FreeFalling: http://wiki.roblox.com/index.php?title=API:Class/Humanoid/FreeFalling

0
Thanks for the answer! TurboFusion 1821 — 8y
Ad
Log in to vote
1
Answered by 3 years ago

I had a solution!, Put a script inside startercharacterscripts then put this isnide the script

local bg = script:WaitForChild("BodyVelocity")

while true do
    wait()
    if script.Parent.Humanoid.FloorMaterial == Enum.Material.Air then
        local vel = script.Parent.Humanoid.WalkSpeed
        bg.Velocity = Vector3.new((script.Parent.Humanoid.MoveDirection.X * (vel + 2)) ,0,(script.Parent.Humanoid.MoveDirection.Z * (vel + 2)))
        bg.MaxForce = Vector3.new(script.Parent.Humanoid.WalkSpeed + 100000 , 0 , script.Parent.Humanoid.WalkSpeed + 100000)
        script.Parent.Humanoid.WalkSpeed = 0
        bg.Parent = script.Parent.Torso
        repeat wait() until script.Parent.Humanoid.FloorMaterial ~= Enum.Material.Air
        script.Parent.Humanoid.WalkSpeed = vel
        bg.Parent = script
    end
end

and then, Put a body velocity parented with the script and done! It worked for me! (R6 only, Change all torso for humanoidrootpart if it is r15 or a custom rig!)

Log in to vote
0
Answered by 8 years ago

I'd recommend changing the walk speed properties or changing the controller service to "NIL".

Answer this question