Billboard gui only check player position

I want to know how I would go about making a billboard gui where if its a certain distance away from the player it will show but does not check the camera

Basically i want it so if the camera is further away itll show no matter what and with regular maxdistance it checks the camera

Camera and player close to part

Camera further away but player in the same spot
image

1 Like

You can use a Script which checks the Distance between the Player(s) Head or Torso from the Point of Interest.

When in range of the point of interest the GUI would be visible.

ah ok ill try that and get back to you

1 Like

well i already have one question

if i checked that on the server script it would show for everyone

Using a Local script or Local Event you can have it show only for the player, however you can have it show for the entire server ( which I don’t recommend doing )

For instance, local script would make the GUI visible only towards that player when in range.

& (server script) for instance having it show up when a player is in range would show on everyone’s screens, when they aren’t near the point of interest.

this is what i made but how can i optimize this so i dont have to make tons of scripts for every single gui i want this for

while wait() do
	if (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - script.Parent.Parent.Position).Magnitude <= 10 then
		script.Parent.Visible = true
	end
end

You can have this in 1 script, usually placing it in Starter Gui is best ( when using Local Scripts )

you can duplicate that code in the same script but with what ever it’s supposed to do.

For Example:

i see, ill check this out and let you know

Not sure my scripting is correct, but it’s just a example.
PS- i just edited it since i noticed a few mistakes, there might be more.

You can use this inRange() function to see if the player is in the range.

local function inRange(player, position, range)
	if not player then return end
	if not player.Character then return end
	if not player.Character:FindFirstChild("HumanoidRootPart") then return end
	if not position then return end
	if not range then return end
	return (position - player.Character.HumanoidRootPart.Position).Magnitude <= range
end

You can use Modules or CollectionService for that.

What have you done is very inefficient. Never have multiple loops like this. They unnecessary, put everything that needs to be looped in one loop.

local function inRange(player, position, range)
	if not player then return end
	if not player.Character then return end
	if not player.Character:FindFirstChild("HumanoidRootPart") then return end
	if not position then return end
	if not range then return end
	return (position - player.Character.HumanoidRootPart.Position).Magnitude <= range
end

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local GuiSpots = workspace.GuiSpots:GetChildren() -- Get the folder that stores all the spots where the gui must appear
local Frame = script.Parent -- Your frame location

RunService.Heartbeat:Connect(function()
	local isInRange = false
	for _, v in pairs(GuiSpots) do
		if inRange(Players.LocalPlayer, v.Root.Position, 10) then
			isInRange = true
			break
		end
	end
	Frame.Visible = isInRange
end)

2 Likes

I changed some stuff to fit my billboard gui and since i have multiple uis i added another variable and it all seems to work fine

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local GuiSpots = workspace.Eggs.GuiSpots:GetChildren() -- Get the folder that stores all the spots where the gui must appear

Players.LocalPlayer.CameraMaxZoomDistance = 35

local function inRange(player, position, range)
	if not player then return end
	if not player.Character then return end
	if not player.Character:FindFirstChild("HumanoidRootPart") then return end
	if not position then return end
	if not range then return end
	return (position - player.Character.HumanoidRootPart.Position).Magnitude <= range
end

RunService.Heartbeat:Connect(function()
	local isInRange = false
	local frameInRangeOf
	for _, v in pairs(GuiSpots) do
		if inRange(Players.LocalPlayer, v.Position, 10) then
			isInRange = true
			frameInRangeOf = v.HatchBBGui
			break
		end
	end
	if frameInRangeOf ~= nil then
		frameInRangeOf.Enabled = isInRange
	else
		for _, v in pairs(GuiSpots) do
			if v.HatchBBGui.Enabled == true then
				v.HatchBBGui.Enabled = false
			end
		end
	end
end)
1 Like