How do I position a 2d screengui frame on a 3d part?

So I’m trying to make a quest system where it displays on icon where a Vector3 position is, but the icon is a gui from the screengui. How can I make the icon position on a Vector3 position?

i think this is what you might be looking for

2 Likes

No, this is better

2 Likes

yeah i kinda remembered that one, searched it up and thought they changed its name or something, definitely better one

1 Like

That function is not necessarily better; it depends on whether or not the container of the element you want to position ignores the GUI inset in its positioning or not.

Camera:WorldToViewportPoint should be used to calculate the 2D position from the world position on the entire viewport, so it ignores the GUI inset. For example, if the element you want to position is inside a ScreenGui with ScreenGui.IgnoreGuiInset enabled, you’d use this method.

When you want to calculate the 2D position from the world position on the screen, which takes into account the GUI inset (starts at the bottom of the inset and stops at the bottom of the screen), Camera:WorldToScreenPoint should be used instead.

cc @Wingboy0

8 Likes

You can make a script like this:

local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local YourCharacter = workspace.TheNameOfYourCharacter
local Position = YourCharacter.Head.Position
local vector, onScreen = camera:WorldToScreenPoint(worldPoint)
local ScreenGui = Instance.new("ScreenGui", Player.PlayerGui)
local Gui = Instance.new("Frame", ScreenGui)
Gui.Position = UDim2.fromOffset(vector.x, vector.y)

Edit:

local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local YourCharacter = workspace.TheNameOfYourCharacter
[[--local Position = YourCharacter.Head.Position
local vector, onScreen = camera:WorldToScreenPoint(worldPoint)--]]
local ScreenGui = Instance.new("ScreenGui", Player.PlayerGui)
local BillboardGui = Instance.new("BillboardGui", ScreenGui)
BillboardGui.Adornee = YourCharacter.Head
Billboard.StudsOffsetWorldSpace = UDim2.fromOffset(0, 2.5)
local Gui = Instance.new("Frame", BillboardGui)
Gui.AnhoredPoint = Vector2.new(0.5, 0.5)
1 Like