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

How do I get a conditional statement with FloorMaterial being Air?

Asked by
Launderer 343 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
With what you need help? `If FloorMaterial = Enum.Material.Air then` do the code that's all. superalp1111 662 — 6y
0
That's the same as first Script, just identify the Materials of your ground, change 'Air' into Type of Material of your ground User#17685 0 — 6y
0
To have it stop you would do Character.HumanoidRootPart.BodyVelocity:Destroy() or :Remove() TiredMelon 405 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
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)
Ad

Answer this question