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

How can you tell if a person is above a part?

Asked by 8 years ago

I would like to close a Gui when a player is not over or under a brick. This means using part.Position and part.Size. Is there a way to combine these two and use .magnitude to make this statement false?

player=game.Players.LocalPlayer
flor=game.Workspace.flor

while wait(1) do
    if not(player:DistanceFromCharacter(flor.Position)><=?) then
        script.Parent.Parent.Visible=false
    end
end
0
Are you wanting to do this only when the player is touching the brick or do you want to do this whenever the player is directly above / below the brick? NoahWillCode 370 — 8y
0
What do you mean by "over"? In any of the space above? Even if there's another floor between you and the `flor` part? Only standing directly on it? BlueTaslem 18071 — 8y
0
if the player is between the x and z coordinates of the part. BobserLuck 367 — 8y
0
I could do a couple of if statements but I'd rather not. BobserLuck 367 — 8y
0
Have you tried using a Region3 and just setting the Y value of the player's character to the Y of the brick so that you don't have to check that? http://wiki.roblox.com/index.php?title=API:Region3 NoahWillCode 370 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Maybe you can cast a ray above the brick to determine if the character is directly above. Here is some sample code.

local Part = workspace:WaitForChild("PARTNAMEHERE")

Part.Touched:connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") ~= nil then
        local Ray = Ray.new(Part.Position,Part.Position + Vector3.new(0,50,0))
        local Hit,Position = workspace:FindPartOnRay(Ray)

        if Hit then
            -- Your code here
        end
    end
end
Ad

Answer this question