Im looking to make an interaction system for one of my games, and I want to make it so only the closest single billboardgui is visible to the player (locally)
BUT… this happens
Im looking to make it look like this
so basically all im trying to do is remake proximity prompts without using proximity prompts
my code is here if game:GetService(“Players”).LocalPlayer.Character:FindFirstChild(“Humanoid”) then
for i, v in pairs(workspace.Interactions:GetDescendants()) do
if v:IsA(“BillboardGui”) then
function distance(x1,y1,z1,x2,y2,z2)
local d = math.sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2 + (z1 - z2) ^ 2)
return d
end
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local function getNearest()
local nearest = v
local shortest = math.huge
for i,v in pairs(workspace.Interactions:GetDescendants()) do
local distance = distance(humanoid.Head.Position.X, humanoid.Head.Position.Y, humanoid.Head.Position.Z, v.Position.X, v.Position.Y, v.Position.Z)
if distance < shortest then
nearest = v
shortest = distance
end
end
return nearest
end
local nearest = getNearest()
local dist = distance(humanoid.Head.Position.X, humanoid.Head.Position.Y, humanoid.Head.Position.Z, nearest.Position.X, nearest.Position.Y, nearest.Position.Z)
if dist <= 20 then
v.Enabled = true
else
v.Enabled = false
end
end
end
end
The answer is very simple, you just need to change your code to only check the distance of the character’s head and the billboard GUI if the billboard GUI is enabled. local function getNearest()
local nearest = v
local shortest = math.huge
for i,v in pairs(workspace.Interactions:GetDescendants()) do
if v.Enabled then
local distance = distance(