Still have questions? Join our Discord server and get real time help.
Log in to vote

Is there a script to check for player's y position distance from a map?

Asked by 7 months ago

The map's height rises at a point and descends at another. It is bigger than 5 max sized baseplates. Is there any way to check the player's distance in the y position from the actual map?

I'm confused on what you're trying to do but you could just subtract the player's y position from whatever to check or use Magnitude to get the distance but it won't only be on the y axis. MythicalShade 420 — 7mo

1 answer

Log in to vote
Answered by 7 months ago

From what I'm guessing I think you are saying you have like a map with varying heights like hills and stuff and you want to know how far the character is from the point on the map below them. To get that you would have to use raycast. Its pretty simple but if you only want to decect the map you would have to group the map into one model if its not terrain. Your script would look something like this:

local map = workspace.Map -- holds the map you want to check the height from
function GetHeightRelativeToMap(character)
    local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")
    local startPoint = HumanoidRootPart.CFrame.p
    local Direction =,-1,0) * 300 -- anything greater than like 600 might cause lag.
    local DownRay =,Direction)
    local hit,Position = workspace:FindPartOnRayWithWhiteList(DownRay,{map,workspace.Terrain}) -- if you only wanted to use terrain don't include the map in the whitelist table.
    if hit then
        return HumanoidRootPart.Position.Y - Position.Y
        -- no map underneath the player so return nothing or maybe like math.huge or maybe just there y position
    return HumanoidRootPart.Position.Y


Answer this question