Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

5 comments

0

If Fall animation is playing then do, something like that, idk.

0

'if then do' do you even know how to script

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

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.

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

3 answers

✓ Accepted answer

#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

1 comment

0

Thanks for the answer!

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.