I made a script which is supposed to detect whether the humanoid is touching any material but air; and it doesn’t work. It’s supposed to create a bodypos if it detects air, but the if then function doesn’t work at all.
if Humanoid.FloorMaterial == Enum.Material.Air and aerialBool.Value == false then
aerialBool.Value = true
local bodyPos = Instance.new("BodyPosition")
bodyPos.Parent = HumRP
bodyPos.D = 1250
bodyPos.MaxForce = Vector3.new(0, 600000, 0)
bodyPos.P = 10000
bodyPos.Position = HumRP.Position + Vector3.new(0, 8, 0)
Debris:AddItem(bodyPos, BlueTime + 1)
wait(3.3)
aerialBool.Value = false
end
I put this in the middle of my code to detect real quick whether the human is on the ground or not, and it never detects anything, as if it doesn’t want to. Is this because I used a client property? If so, what server property can I use because I want to stay on the server. I tried using a localscript but it affected all players that happened to be in the air at the time of running so that doesn’t work.
FloorMaterial’s update time isn’t the fastest, if you select the humanoid while play testing you’ll see that the material isn’t air for while, I would recommend sending a raycast from the HumanoidRootPart’s position straight down for 3.1 studs and use that to detect a floor
if you need help setting up the raycast I would do:
local Character -- Character reference (idk how you reference the character
game:GetService("RunService").Stepped:Connect(function()
local RayOrigin = Character.HumanoidRootPart.Position
local RayDirection = Vector3.new(0,-3.1,0)
local RayParams = RaycastParameters.new()
RayParams.FilterType = Enum.RaycastFilterType.Include
RayParams.FilterDescendants = {Character}
local RayCast = workspace:RayCast(RayOrigin, RayDirection, RayParams)
if not RayCast then
-- insert aerial code here
end
end)
some things might be mispelled I didn’t use a code editor for autocompletes
3 will almost never return anything as the height from the humanoid root part’s position to the ground is exactly 3 studs, and you don’t want it detecting too far away so 3.1 is usually a safe bet, you can always do like 3.000001 or something or 4 if you want to detect the ground sooner but if you want precise results I’d say 3.1 is a safe number