How do I make ONLY the closest billboardgui visible?

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
image

Im looking to make it look like this
image

so basically all im trying to do is remake proximity prompts without using proximity prompts

BillboardGuis have a property called MaxDistance.

yes, i know, but even with maxdistance set to something, they’ll all still appear near you

Your stuck at this point, I can’t help you anymore but you can use Magnitude.

im new to scripting, so i dont know how to use magnitude…

You could use a click detector and change the player’s cursor icon when hovering over the part containing the click detector.
For example -

clickDetector = script.Parent
clickDetector.MouseHoverEnter:Connect(function(player)
local mouse = player:GetMouse()
mouse.Icon = "image ID here"
end)
clickDetector.MouseHoverLeave:Connect(function(player)
local mouse = player:GetMouse()
mouse.Icon = "rbxassetid://0"
end)

I too am new to scripting as well so I am sorry if it doesn’t work.
Make sure to put the script inside the click detector btw!

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(