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 9 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 — 9y
0
'if then do' do you even know how to script unmiss 337 — 9y
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 — 9y
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 — 9y
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 — 9y

3 answers

Log in to vote
1
Answered by 9 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:

01local plr = game.Players.LocalPlayer
02local chr = plr.Character or plr.CharacterAdded:wait()
03local hum = chr:FindFirstChild("Humanoid")
04local falling = false
05 
06    hum.FreeFalling:connect(function(isFalling)
07        falling = isFalling
08        if isFalling then
09            while falling do
10                print("Falling!")
11                wait()
12            end
13        else
14            print("Not Falling!")
15        end
16    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.

01local plr = game.Players.LocalPlayer
02local chr = plr.Character or plr.CharacterAdded:wait()
03local hum = chr:FindFirstChild("Humanoid")
04local falling = false
05 
06    hum.FreeFalling:connect(function(isFalling)
07        falling = isFalling
08        if isFalling then
09            while falling do
10                hum.WalkSpeed = 0;
11                wait()
12            end
13        else
14            hum.WalkSpeed = 16;
15        end
16    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 — 9y
Ad
Log in to vote
1
Answered by 4 years ago

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

01local bg = script:WaitForChild("BodyVelocity")
02 
03while true do
04    wait()
05    if script.Parent.Humanoid.FloorMaterial == Enum.Material.Air then
06        local vel = script.Parent.Humanoid.WalkSpeed
07        bg.Velocity = Vector3.new((script.Parent.Humanoid.MoveDirection.X * (vel + 2)) ,0,(script.Parent.Humanoid.MoveDirection.Z * (vel + 2)))
08        bg.MaxForce = Vector3.new(script.Parent.Humanoid.WalkSpeed + 100000 , 0 , script.Parent.Humanoid.WalkSpeed + 100000)
09        script.Parent.Humanoid.WalkSpeed = 0
10        bg.Parent = script.Parent.Torso
11        repeat wait() until script.Parent.Humanoid.FloorMaterial ~= Enum.Material.Air
12        script.Parent.Humanoid.WalkSpeed = vel
13        bg.Parent = script
14    end
15end

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 9 years ago

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

Answer this question