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

How to tell if the player is touching the ground?

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.

4 comments

0

There is no good solution for this. I try a combination of position checks, velocity checks, and raycasts.

0

Idiots. Just use the FindFirstChild() method on a Part with Grass terrain on it and you're good to go.

0

DeceptiveCaster no

3 answers

✓ Accepted answer

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 comments

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!

0

^Very important

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.

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 

2 comments

0

dog sh#t

0

chill

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