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
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 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)
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)