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 get a conditional statement with FloorMaterial being Air?

Okay I need some help here. Basically I need it so if the player is in the air it creates a bodyvelocity to push them to the ground. I felt that FloorMaterial would be the correct way to do this however I'm not seeing a lot of information about it on the wikis and what not. I found out that if you arn't standing on anything the FloorMaterial is Air. So if someone can help me with this it'd be much appreciated.

if Character.Humanoid.FloorMaterial == Enum.FloorMaterial.Air then
local Gravity = Instance.new("BodyVelocity", Character.HumanoidRootPart)
Gravity.Name = "Gravity"
Gravity.Velocity = Vector3.new(0, -2, 0)
Gravity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
end

edit:

Okay so I just discovered the FreeFalling event, https://wiki.roblox.com/index.php?title=API:Class/Humanoid/FreeFalling It work's and all however I don't know how to stop it when they hit the ground so if someone could now advise me on that I'd be all set.

Character.Humanoid.FreeFalling:connect(function()
local Gravity = Instance.new("BodyVelocity", Character.HumanoidRootPart)
Gravity.Name = "Gravity"
Gravity.Velocity = Vector3.new(0, -2, 0)
Gravity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
end)

3 comments

0

With what you need help? If FloorMaterial = Enum.Material.Air then do the code that's all.

0

That's the same as first Script, just identify the Materials of your ground, change 'Air' into Type of Material of your ground

0

To have it stop you would do Character.HumanoidRootPart.BodyVelocity:Destroy() or :Remove()

1 answer

✓ Accepted answer
Character.Humanoid.FreeFalling:connect(function()
	local Gravity = Instance.new("BodyVelocity", Character.HumanoidRootPart)
	Gravity.Name = "Gravity"
	Gravity.Velocity = Vector3.new(0, -1, 0)
	Gravity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	repeat wait() until Character.Humanoid.FloorMaterial ~= Enum.Material.Air
	Gravity:Destroy()
end)

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