self.GuiConnections['loop'] = Runservice.RenderStepped:Connect(function()
if self.ShowGuiOBJECT then
if (not self.Gui.Show.Visible) then
self.Gui.Show.Visible = true
end
local WST = workspace.CurrentCamera:WorldToScreenPoint(workspace.CookingSystem.Ingredients:FindFirstChild(self.StepInformation[self.Step]).Position)
self.Gui.Show.Position = UDim2.new(0,WST.X,0,WST.Y)
end
end)
You need to account for the size of the UI object:
self.GuiConnections['loop'] = Runservice.RenderStepped:Connect(function()
if self.ShowGuiOBJECT then
if (not self.Gui.Show.Visible) then
self.Gui.Show.Visible = true
end
local WST, isOnScreen = workspace.CurrentCamera:WorldToScreenPoint(workspace.CookingSystem.Ingredients:FindFirstChild(self.StepInformation[self.Step]).Position)
if isOnScreen then
local size = self.Gui.Show.AbsoluteSize
self.Gui.Show.Position = UDim2.new(0, WST.X - size.x/2, 0, WST.Y - size.y/2)
end
end
end)
Similarly, an instance’s position (in this case, the part you’re referencing as a cooking object), is the centre of the object - you need to offset that position if you want it above / below.
Not only that, but you need to interpolate the size of the UI object based on the distance of the object to the screen - otherwise if you’re hundreds of studs away from the object, the UI object will still be just as large as it is. You can achieve this like:
local MAX_DISTANCE = 50
local NORMAL_SIZE = self.Gui.Show.Size
self.GuiConnections['loop'] = Runservice.RenderStepped:Connect(function()
if self.ShowGuiOBJECT then
if (not self.Gui.Show.Visible) then
self.Gui.Show.Visible = true
end
local WST, isOnScreen = workspace.CurrentCamera:WorldToScreenPoint(workspace.CookingSystem.Ingredients:FindFirstChild(self.StepInformation[self.Step]).Position)
if isOnScreen and WST.z <= MAX_DISTANCE then
local depth = WST.z
self.Gui.Show.Size = NORMAL_SIZE * (depth / MAX_DISTANCE)
local size = self.Gui.Show.AbsoluteSize
self.Gui.Show.Position = UDim2.new(0, WST.X - size.x/2, 0, WST.Y - size.y/2)
end
end
end)
local MAX_DISTANCE = 50
local NORMAL_SIZE = self.Gui.Show.AbsoluteSize
self.GuiConnections['loop'] = Runservice.RenderStepped:Connect(function()
if self.ShowGuiOBJECT then
if (not self.Gui.Show.Visible) then
self.Gui.Show.Visible = true
end
local WST, isOnScreen = workspace.CurrentCamera:WorldToScreenPoint(workspace.CookingSystem.Ingredients:FindFirstChild(self.StepInformation[self.Step]).Position)
if isOnScreen and WST.z <= MAX_DISTANCE then
local depth = WST.z
local cur = NORMAL_SIZE * (depth / MAX_DISTANCE)
self.Gui.Show.Size = UDim2.new(0, cur.x, 0, cur.y)
local size = self.Gui.Show.AbsoluteSize
self.Gui.Show.Position = UDim2.new(0, WST.X - size.x/2, 0, WST.Y - size.y/2)
end
end
end)