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

Make a gui's position relative to a bricks position?

Alright, I have edited my code:

local camera = workspace.CurrentCamera
while true do
	wait()
	local pos = camera:WorldToScreenPoint(workspace.TestPart.Position)
	local screenpoint = Vector2.new(pos.X,pos.Y)
	script.Parent.Position = UDim2.new(screenpoint)
end

its a lot better, but the frame wont move. when I put print(screenpoint), it returns with coordinates with where the frame would go, but when I change its position to screenpoint, it doesn't move at all. Why is this?

1 answer

✓ Accepted answer

there's no need to use complicated math for this, you can just use a BillboardGui

https://developer.roblox.com/en-us/api-reference/class/BillboardGui

although, if what i think you're doing is correct, you're trying to get the gui to display even if the actual object is offscreen...which you still don't need complicated math for

you can just use Camera:WorldToViewportPoint (or WorldToScreenPoint if you aren't accounting for the gui inset) to get the position of the object in screen space, then clamp the value to make sure it doesn't go offscreen

4 comments

0

ill try to use this

0

ok i edited my question if you could tell me why my code wont work that would be nice

0

you can't create a UDim2 with a Vector2, you have to manually put UDim2.new(0, vector.X, 0, vector.Y)

0

you can't create a UDim2 with a Vector2, you have to manually put UDim2.new(0, vector.X, 0, vector.Y)

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