Need help with :WorldToScreenPoint()

In my game I’m trying to place boarders around a boxed area to prevent the players from seeing outside of it that scales with whatever resolution you have.

The problem is the boarders won’t position correctly. they seems to be weirdly upwards offset


When I need them to be directly in the center of the parts
aka these

Here is the code used to position the gui objects(it is basically the same for all the boarders)

local TBoarder = -- This is the gui object
function TB()
	local CurrentMap = workspace:FindFirstChild("Map"..Map.Value)-- This is the model in workspace with the parts
	local pos, isOnScreen = camera:WorldToScreenPoint(CurrentMap.TBoarder.Position+Vector3.new(-2,0,0))
	if isOnScreen then
		TBoarder.Visible = true
		TBoarder.Position = UDim2.new(0,pos.X,0,pos.Y)
	else TBoarder.Visible = false
	end
end

I have tried setting some offsets manually but they never scale correctly(the -2 x is for the thickness, removing it does not help anything)

If anyone knows what is going on that would help lots!

I just realized what might be the problem.

https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToViewportPoint

Camera:WorldToViewportPoint is a more accurate representation of the viewport. Camera:WorldToScreenPoint doesn’t take into account the topbar at the top of the screen.

Or alternatively turn the IgnoreGuiInSet off in your ScreenGui object

4 Likes

this actually fixed the issue as i had IgnoreGuiInSet on :+1:

1 Like