I want the text button or really any GUI for my api to correctly follow the NPC, I use BillBoardGui for other things like name tags but I want a button or smth but when you parent a button to the bill board which is a child of the model it doesn't work.
function UIComponent:FollowWorldPosition(target, offset, maxDistance)
offset = offset or Vector3.new(0,0,0)
local maxDist = maxDistance or math.huge
local conn = RunService.RenderStepped:Connect(function()
local worldPos = (typeof(target) == "Instance" and target.Position) or target
local screenPoint, onScreen = workspace.CurrentCamera:WorldToViewportPoint(worldPos + offset)
local camPos = workspace.CurrentCamera.CFrame.Position
local dist = (worldPos - camPos).Magnitude
if onScreen and dist <= maxDist then
local viewport = workspace.CurrentCamera.ViewportSize
self.Instance.Position = UDim2.new(
screenPoint.X / viewport.X, 0,
screenPoint.Y / viewport.Y, 0
)
self.Instance.Visible = true
else
self.Instance.Visible = false
end
end)
self._worldPosConn = conn
return self
end