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

How to tell if the player is touching the ground?

Asked by 6 years ago

So I have a shovel tool and I only want it to activate if the player is touching the ground (not jumping, falling, etc.). Is there some code that Roblox has for identifying if the player is on the ground or is there some way I could make a script for this. Im not familiar with any commands that would make this work. Please help if you can.

0
There is no good solution for this. I try a combination of position checks, velocity checks, and raycasts. cabbler 1942 — 6y
0
Idiots. Just use the FindFirstChild() method on a Part with Grass terrain on it and you're good to go. DeceptiveCaster 3761 — 6y
0
DeceptiveCaster no romoney5 0 — 3y

3 answers

Log in to vote
5
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

Humanoid.FloorMaterial

http://wiki.roblox.com/index.php?title=API:Class/Humanoid/FloorMaterial

Description : This property contains the Material of the part or terrain cell that the Humanoid is currently standing on (as calculated in the last Humanoid step). If the Humanoid is not currently standing on any part the value of the property would be Material of Air.

try this:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hum = character.Humanoid
local rs = game:GetService("RunService")

rs.RenderStepped:Connect(function()
    if hum.FloorMaterial ~= nil then
        print('Standing on '..hum.FloorMaterial.Name)
    else
        print('Not standing on the floor')
    end
end)
2
understand that this was a year ago, but I was recently using this to prevent the player from using a movement action whilst in the air! making it only work if the floor material is not "nil" no longer functions correctly, and you'd instead have to make the argument "hum.FloorMaterial ~= Enum.Material.Air". I understand this probably worked a year ago, but now it doesn't. thanks! x_Tso 48 — 4y
0
^Very important Klamman 220 — 3y
Ad
Log in to vote
0
Answered by 6 years ago

Sorry about the late reply, but after much testing I got chexyalani’s system to work for my purposes. Btw the other answers are bad, but chexyalani’s answer is definitely the way to go for anyone who is looking for a solution. You can easily modify it to run when you need it to. Thx chexyalani.

Log in to vote
-2
Answered by 6 years ago

This will check how far away a player is from the floor you can mess with the numbers and names to what you wish.

((game.Floor.Position+Vector3.new(0,1,0)) Character.HumanoidRootPart.Position).magnitude <=1 
0
dog sh#t iuclds 720 — 4y
0
chill Uzixt 19 — 3y

Answer this question