Moving part with gui

  1. So what i mean by the title is how can i move a 3d world part when moving a 2d gui

  2. I have idea how i would achieve this but i just dont know how could i make it work, so basically i made same sized boxes, 3d world and 2d gui, the only difference is one is in studs and other one in pixels, i thought about getting the middle scale or ratio between the both sizes so for example if you move a gui 10 pixels, the part moves 0.1 studs.

any help or script example will be appreciated.

This worked for me.

wont this make the part go over the allowed borders when moving the gui?

Not sure, did some testing with camera:WorldToScreenPoint and it sorta worked.

while true do
local camera = workspace.CurrentCamera
local gui = script.Parent

local worldPoint = workspace.Part.Position
-- Change worldpoint's position to the position you wanna test
local vector, onScreen = camera:WorldToScreenPoint(worldPoint)

	gui.Position = UDim2.new(gui.Position.X.Scale, vector.X, gui.Position.Y.Scale, vector.Y)
	task.wait(.1)
end

The only reason I put the code in a while loop was so that it constantly follows the position (testing purposes), but obviously you shouldn’t as it’d take up resources.

Try this in your own baseplate with your own worldpoint and see if it’s like how you want.