How to make a SurfaceGui act like a ScreenGui?

Hello,
I am trying to make a SurfaceGui function similarly to a ScreenGui, positioning it onto the player’s screen.
Here’s the screenshot of what the SurfaceGui should look after:

3 Likes

Have you tried using a viewport frame?

I don’t really know how to do that. I have tried.

1 Like

edited script from this topic

local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local UI = workspace.UI -- your SurfaceGui Part

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

game:GetService("RunService").PreRender:Connect(function()
	local ray = camera:ScreenPointToRay(mouse.ViewSizeX/2, mouse.ViewSizeY/2,  10)
	UI.CFrame = CFrame.lookAt(ray.Origin + ray.Direction, camera.CFrame.Position)
end)
1 Like

You can find info about it here: ViewportFrame | Documentation - Roblox Creator Hub