Hello there,
So I am having trouble with my distance script everytime I make it where if the billboard is not enabled I set it to textLabel.Text = ""
it breaks the script but when I remove that part it works idk why it’s doing it but I can’t seem to fix it.
Working script
local Destinations = {}
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local textLabel = script.Parent
local function updateDistance(part)
if part.BillboardGui.Enabled then
local distance = (player.Character.HumanoidRootPart.Position - part.Position).Magnitude
textLabel.Text = distance > 1000 and string.format("%.1f mi", distance / 1000) or string.format("%.1f ft", distance)
end
end
for _, folder in ipairs(game.Workspace:GetChildren()) do
if folder.Name:match("Destinations$") then
for _, destination in ipairs(folder:GetChildren()) do
table.insert(Destinations, destination)
end
end
end
while true do
for _, destination in ipairs(Destinations) do
updateDistance(destination)
end
wait(0.01)
end
Broken script
local Destinations = {}
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local textLabel = script.Parent
local function updateDistance(part)
if part.BillboardGui.Enabled then
local distance = (player.Character.HumanoidRootPart.Position - part.Position).Magnitude
textLabel.Text = distance > 1000 and string.format("%.1f mi", distance / 1000) or string.format("%.1f ft", distance)
else
-- This is where it breaks the script!
textLabel.Text = ""
end
end
for _, folder in ipairs(game.Workspace:GetChildren()) do
if folder.Name:match("Destinations$") then
for _, destination in ipairs(folder:GetChildren()) do
table.insert(Destinations, destination)
end
end
end
while true do
for _, destination in ipairs(Destinations) do
updateDistance(destination)
end
wait(0.01)
end
If someone could help me what the problem is that would be really helpful
@Sim_Q1