How can I make a billboard gui only appear at a certain distance

ive got these billbaord gui’s in my game that tell the player what button to press to interact with an object

I only want 1 to be visible at a time but the problem is its a 2d platformer so the camera is locked to the front veiw

build board gui display distance is based of the camera not were the player is so if the billboard gui is in the players screen is it visible

how can I make it dissapear when the players character gets a certain distance away

1 Like

BillboardGui.MaxDistance = [STUDS]

2 Likes

thats the same thing I already had

max distance is how far the camera is from the part but the problem is the camera is always the same distance since its locked to a front view

its gotta be how far away the player is

Place this localscript inside billboardgui:

local plr = game.Players.LocalPlayer
local rs = game:GetService("RunService")
local gui = script.Parent
local part = gui.Adornee or gui.Parent

local function calcDistance(a:BasePart,b:BasePart)
	local pos1,pos2 = a.Position,b.Position
	local dif = pos1-pos2
	return dif.Magnitude
end

rs.RenderStepped:Connect(function()
	local char = plr.Character
	
	if char then
		local ppart = char.PrimaryPart
		
		if ppart then
			local d = calcDistance(part,ppart)
			
			if d > gui.MaxDistance then
				gui.Enabled = false
			else
				gui.Enabled = true
			end
		end
	end
end)
1 Like

ill try this sry wasnt on to much

doesnt seem to work does the same thing

This script using MaxDistance to hide gui. Do you set it?

what line do I set it?

Just change gui.MaxDistance to needed number

1 Like

hmm still doesnt work

Wait and I provide fixed script

1 Like

I found error: Localscripts in workspace doesn’t work, but serverscripts does!
Place my script in local enviroment like StarterGui or StarterCharacterScripts (StarterPlayerScripts). Don’t forgot for change gui path to needed. Use in this case workspace:WaitForChild(“NAME”) for get part because I got error (X is not child of workspace) while testing

1 Like

ill try and see if this works

changed the variable ima see if this works
also we might need to do a loop since theres multiple of these billboard ui’s

did this doesnt work

Any error outputs and where script is in? This script working for me, but I can fix your error

If you have some guis you can make for i,v in pairs(SOMEGUISTABLE)

oh ya sry for late responses

image

Wrap “Carrot” into WaitForChild() and it must to be work!

I dont see were it says wait for child do I add it

Script executes faster than workspace and you need to:

local gui = game.Workspace.HubWorld.Consumables.Carrots:WaitForChild("Carrot").EPrompt
1 Like