# How to check if someone is far away enough from the ground?

I’m trying to make a lightning drop move, where it drops the player to the ground if they are high up, but how would I check if they aren’t just jump height, and how would I teleport them down to the location? I think this has something to do with rays, but i’m not sure how to use it, but I use this function for rays.:

``````function ray(startpos, endpos, dis)
local Ignore = {game.Workspace.Players}
local test = Ray.new(startpos, CFrame.new(startpos, endpos).lookVector * dis)
local hit, pos, sf = game.Workspace:FindPartOnRayWithIgnoreList(test,Ignore)
return hit, pos, sf
end
``````

To provide more context: If a player jumps, from that height they cannot activate the drop. If they are on a tall brick and jump from there (off the ground), it would activate. Let me know if anyone needs more context to what i’m trying to do…

Raycast with the origin being the rootpart position of the player and the direction being something like `Vector3.new(0, -1000, 0)`. If the ray hits something, then teleport them to the ray hit position

1 Like

…But wouldnt that let them do it from any height?

You can check the magnitude between the origin of the ray and the ray’s hit position

1 Like

Could I get an example? I’m not sure how to create that

``````local Origin = RootPart.Position
-- you should also add raycast params to ignore your character and whatever other parts you need to ignore
local Result = workspace:Raycast(Origin, Vector3.new(0, -1000, 0))

-- check if ray hit anything
if Result then
local Distance = (Origin - Result.Position).Magnitude
-- if distance between rootpart and ground below is more than 10
if Distance > 10 then
-- do lightning move
end
end
``````
1 Like

Would this work?

``````local Origin = RootPart.Position
function ray(startpos, endpos, dis)
local Ignore = {game.Workspace.Players}
local test = Ray.new(startpos, CFrame.new(startpos, endpos).lookVector * dis)
local hit, pos, sf = game.Workspace:FindPartOnRayWithIgnoreList(test,Ignore)
return hit, pos, sf
end
local h,p,sf = ray(Origin+ Vector3.new(0,8,0), char.HumanoidRootPart.CFrame * CFrame.new(0,-1000,0).p, 12)
if h then
local Distance = (Origin - h.Position).Magnitude
if Distance > 10 then
-- do stuff
``````

You should use `workspace:Raycast` since `FindPartOnRay` is deprecated. Also you need to update the origin each time you use the lightning move (so probably put the “Origin” variable inside of the move function if you have one)

1 Like

So replacing that and such, it would work correctly?

Assuming you defined “RootPart” as the HumanoidRootPart above in your script then yes. Also, if you wanted to teleport to where the ray hit then you can just set the RootPart’s CFrame to the hit position of the ray

1 Like

So I would set the rootpart’s position to h.Position?

If you insist on using `workspace:FindPartOnRay` then you should just use “p”. `FindPartOnRay` returns a tuple which has the `hitPart` and the `hitPosition`, and your 2nd variable “p” is the hitPosition

1 Like

I am trying out workspace:Raycast(theray, ignorelist)

`workspace:Raycast` is a little bit different, look at the documentation

2 Likes

I see, I would stick to FindPartOnRay, I would define hit’s position by simply h.p, and then set the humanoidrootpart by Position, right?

No, literally “p” is the hit position of the ray. You can try setting the rootpart’s position to “p” (btw you should probably add an offset so the character teleports a little bit higher than the hit position so players don’t get potentially stuck in the ground)

1 Like

Thank you! I will let you know how it goes.

``````local ground = -- were
local root = -- were

local dist = root.Position.Y - ground.Position.Y

print(dist < 3 and 'the player is standing [or no?]' or 'the player is 100% not standing')
``````
1 Like

So nothing is erroring or printing, but nothing is happening even if i’m falling from a good height: Here’s my code

``````local MainModule = require(game.ServerScriptService.Modules.MainModule)
local cd = false
function ray(startpos, endpos, dis)
local Ignore = {game.Workspace.Players}
local test = Ray.new(startpos, CFrame.new(startpos, endpos).lookVector * dis)
local hit, pos, sf = game.Workspace:FindPartOnRayWithIgnoreList(test,Ignore)
return hit, pos, sf
end
local Origin = Root.Position
local h,p,sf = ray(Origin+ Vector3.new(0,8,0), Root.CFrame * CFrame.new(0,-1000,0).p, 12)
if h then
local Distance = (Origin - p).Magnitude
if Distance > 10 then
print("yahee")
Root.Position = p * Vector3.new(0,1,0)