At the moment I have 4 buttons, but looking at the green one in particular. When you click and hold this button down it allows you to move an object, and the other 3 buttons disappear. Now, I want this button to follow the mouse, which I thought since it’s in a BillboardGui would mean once you clicked the button and move the model around, the button would stay in the right spot, however, it’s not.
I think the reason this is happening is because the green button is not over the same position as the center of the item your trying to move. The button is offset from the model. So when you move your mouse to a cetain position, the PrimaryPart or the center of the model (whichever you are doing) is being moved to the mouse and since the button is offset from the center or PrimaryPart of the model it is no longer in the same position as the mouse. I hope that makes sense.
The easiest solution is to move the green button so that its hovering over the center of the model if your using MoveTo() or make it hover over the PrimaryPart if your using SetPrimaryPartCFrame().
This is a little edgy cuz there is no concrete way to get the screen position of a billboard gui but this might work. Btw this code assumes the BillboardGui centered on its Adornee
local camera = workspace.CurrentCamera
local billboard = --whereever your billboard gui is
local billboardCenter = camera:WorldToViewportPoint(billboard.Adornee)
local billboardTopLeft = Vector2.new(billboardCenter.X - billboard.Size.X.Offset, billboardCenter.Y - billboard.Size.Y.Offset)
local primaryPartXY = camera:WorldToViewportPoint(Model.PrimaryPart.Position)
local buttonPosition = UDim2.new(0, primaryPartXY.X - billboardTopLeft.X, 0, primaryPartXY.Y - billboardTopLeft.Y)
MoveButton.Position = buttonPosition
I think this will work if you want to move the button during the game. If you dont want to do this then you could just have the button permanantly in a place where it would always hover over the PrimaryPart. Hope this helps
local camera = workspace.CurrentCamera
local billboard = script.Parent
local billboardCenter = camera:WorldToViewportPoint(billboard.Adornee) -- ERROR HERE Adorned to a model
local billboardTopLeft = Vector2.new(billboardCenter.X - billboard.Size.X.Offset, billboardCenter.Y - billboard.Size.Y.Offset)
local primaryPartXY = camera:WorldToViewportPoint(Model.PrimaryPart.Position)
local buttonPosition = UDim2.new(0, primaryPartXY.X - billboardTopLeft.X, 0, primaryPartXY.Y - billboardTopLeft.Y)
MoveButton.Position = buttonPosition