How to make a "sticky" GUI?

What are you attempting to achieve? (Keep it simple and clear)
Making (not sure what it is) textlabels or guis that kind of stick to a surface.
What is the issue? (Keep it simple and clear - Include screenshots/videos/GIFs if possible)
Here are some examples:
(Neighborhood war)
https://gyazo.com/26274824e28f882a1ed8396d9c57134b

(Jailbreak)
https://gyazo.com/5b4553e1fd4a7f37cf6ef34a18613edc
https://gyazo.com/09b8f9033dc02a8f8707bad06b9b7bf1

What solutions have you tried so far? (Have you searched for solutions through the Roblox Wiki yet?)
Searched on wiki and google.

How is this possible to achieve? Thanks for any help!

BillboardGuis allow 2D GUI objects to exist in 3D space. The contents always face the camera, and are positioned based on their parent or, if it is assigned, their BillboardGui.Adornee.

2 Likes

I got this for my own game as well, i’d be happy to help.

			local function WorldToScreen(Position, Mouse, Camera)
					local RealPosition = Camera.CoordinateFrame:pointToObjectSpace(Position)
					local Angle = math.atan2(RealPosition.x, -RealPosition.y) 
					local ViewSize = Vector2.new(Mouse.ViewSizeX, Mouse.ViewSizeY) / 2
					if RealPosition.Z < 0 then 
						local ATY = math.tan(Camera.FieldOfView * math.pi / 360)
						local AT1 = Vector2.new(ATY * ViewSize.X / ViewSize.Y, ATY)
						local UPOS = Vector2.new(-RealPosition.x, RealPosition.y) / RealPosition.z
						local SPOS = ViewSize + ViewSize * UPOS / AT1
						if SPOS.x >= 0 and SPOS.x <= Mouse.ViewSizeX and SPOS.Y >= 0 and SPOS.Y <= Mouse.ViewSizeY then
							return SPOS, Angle
						end
					end
					return nil
				end

This function will return a screen position based on a world position.

local pos = WorldToScreen(mouseTarget.Position,utilities.Mouse,game.Workspace.CurrentCamera)

--some label
label.Position = UDim2.new(0,pos.X,0,pos.Y)
6 Likes

This is how i do it.

local UIS = game:GetService("UserInputService");
local key = Enum.KeyCode.E;
local gui = script.BillboardGui;
local plr = game.Players.LocalPlayer;
local char = plr.Character or plr.CharacterAdded:Wait();
local Selected;
local Distance = 6;

local Places = {
	game.Workspace.Place,
}

UIS.InputBegan:Connect(function(k,i)

end)

game:GetService("RunService").Stepped:Connect(function()
	gui.Parent = script;
	for i,v in next,Places do
		if ((v.Pos.CFrame.p - char:FindFirstChild("HumanoidRootPart").CFrame.p).Magnitude <= Distance) then
			gui.Parent = v;
			Selected = v;
		end
	end
end
2 Likes

Hey, thanks for the answer. I’m not so good at all does math.atan, math.tan function etc.
So I guess i’ll just pass and not add it into my game.
TL;DR
More advanced than I thougt.
I guess i’ll just use @Dandystan answer, might not be the perfect way, but i’ll just use magnitude to see if someone is too far away etc. But kinda sucks that I cant use an image but… nevermind

Did they use that for the guns you think?

You could, alternatively, use BillboardGui.MaxDistance, which determines the maximum distance (away from the camera) in which the contents of the container will be visible.

1 Like

Oh, I did not know. Thats even better :slight_smile: Thanks