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

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

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

5 comments

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?

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?

0

if the player is between the x and z coordinates of the part.

0

I could do a couple of if statements but I'd rather not.

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

1 answer

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

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