Gui following part effect

Hello!

How to make a Gui follow a part?

I am trying to find make a Image label follow a part and i scrolled through Devforum and i didn’t find any solutions. The part is very massive and it’s located at 0, 0, 0.

Here is the script

		local ScreenGui = Instance.new("ScreenGui", game.StarterGui)
		
		local SunShine = Instance.new("ImageLabel", ScreenGui)
		SunShine.Size = UDim2.new(0, 30, 0, 30)
		SunShine.BackgroundTransparency = 1
		SunShine.AnchorPoint = Vector3.new(0.5, 0.5)
		SunShine.Image = "rbxassetid://5200654205"
		SunShine.ZIndex = 2

        --??

Any suggestions will help!

1 Like

If you mean make it like on the part just use surface Uis if you want it to rotate use billboard Uis

No i ment like on the screen but the Gui is following the part on the screen

1 Like

Something like this
robloxapp-20220714-2025519.wmv (544.6 KB)

I can’t rly view the video, says copyright some weird stuff when I download? Try gayzo

It’s hard to tell but the white dot is following the star
https://gyazo.com/10bb7b3583ad2d14d0e6be62678e9e53
(I manually moved it)

1 Like

Try this, MUST be in a local script or use RemoteEvents to send the data.

local part = --location to part
local camera = workspace.CurrentCamera
local worldPoint = part.Position
local vector = camera:WorldToScreenPoint(worldPoint)
 
local screenPoint = Vector2.new(vector.X, vector.Y)
local depth = vector.Z 

Set the position from the screenPoint, I think you should use the offset in the UDim2 part, use runService so you can move it smoothly.

3 Likes

You can do this, but you must do this constantly and repeat it.

I would recommend using a BillboardGui instead.

Well it works but it is pointing at nothing??
https://gyazo.com/341b29c1bd0f64646352d735a7fadbeb

He doesn’t want that, read the previous replies.

1 Like

Show me your full code? I didn’t understand anything from the vid, sry if I’m just dumb

Here

local RemoteEvent = game.ReplicatedStorage.SunShineEvent
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local ScreenGui = game.StarterGui.ScreenGui
local SunTexture2 = game.StarterGui.ScreenGui.ImageLabel

RemoteEvent.OnServerEvent:Connect(function(player, part)
	RunService.Heartbeat:Connect(function()
		local Camera = game.Workspace.Camera

		local part = part
		local camera = workspace.CurrentCamera
		local worldPoint = Vector3.new(0, 0, 0)
		local vector = camera:WorldToScreenPoint()

		local screenPoint = UDim2.new(0, vector.X, 0, vector.Y)
		local depth = vector.Z

		SunTexture2.Size = UDim2.new(0,30,0,30)
		SunTexture2.Position = screenPoint
	end)
end)
-- This is the remote event local script
-- I also added the screeengui and the texture to the game because generating didn't work for me 
SunShineEvent:FireServer(Star)	
--  This is inside a MODULE script

Also In the last reply i went into the server not the in the client, so it probably was at 0, 0, 0 but the part wasn’t there.

Here

local worldPoint = Vector3.new(0, 0, 0)

The worldPoint is supposed the be the part position

local worldPoint = part.Position

Thankk you very much now it works!

1 Like

Hey, I tried following along because im trying to create something similar , but when I put it in a script im having an error with this code.

local vector = camera:WorldToScreenPoint()

its saying " Argument 1 missing or nil "

OK I just fixed my own error by reading the creator hub.

local worldPoint = part.Position
local vector, onScreen = camera:WorldToScreenPoint(worldPoint)