I have made a script to put a billboard Gui on a part when the player is in range with it but it’s not working, whats wrong?
local Part = nil
local Mag = nil
local Popup = script:WaitForChild("Popup")
Popup.Parent = Player.PlayerGui
repeat
wait(0.05)
if Player.Character.Humanoid.SeatPart == nil and game:IsLoaded() then
local Items = game.Workspace:GetDescendants()
for _,p in pairs(Items) do
if p.Name == "RemoteEvent" then
local Distance = (p.Position - Player.Character.HumanoidRootPart.Position).Magnitude
if Distance < 5 then
if Part == nil then
Part = p.Parent
Mag = Distance
Popup.Adornee = Part
Popup.Enabled = true
Popup.ClosestPart.Value = Part
elseif Part ~= nil and Part ~= p then
if Distance < Mag then
Part = nil
Mag = nil
Popup.Enabled = false
wait(0.025)
Part = p.Parent
Mag = Distance
Popup.Adornee = Part
Popup.Enabled = true
end
end
elseif Distance >= 5 or Distance >= Mag then
if p.Parent == Part then
wait(.1)
Part = nil
Popup.Adornee = nil
Popup.Enabled = false
elseif Part == nil then
v4 = nil
Popup.Adornee = nil
Popup.Enabled = false
Popup.ClosestPart.Value = nil
end
end
end
end
else
if game:IsLoaded() then
v3 = nil
Popup.Adornee = nil
Popup.ClosestPart.Value = nil
Popup.Enabled = false
Mag = nil
end
end
until script.Disabled == true
Go to the bottom section to skip the debugging section.
I don’t use billboard guis that often so i might be wrong but it seems to me that there’s an issue with billboard guis, the localscript does indeed make it visible but for some reason, it doesn’t show up. If you manually try to see the properties of the “Frame”, it does change the visibility to true and false depending on the distance.
Location:
.
Code:
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local CurrentCamera = Workspace["CurrentCamera"]
local Billboard = Workspace:FindFirstChild("Part")["BillboardGui"] -- Billboard
local Frame = Billboard:FindFirstChild("Frame") -- Frame
local HumanoidRootPart = script["Parent"]:WaitForChild("HumanoidRootPart")
RunService["RenderStepped"]:Connect(function()
Frame["Visible"] = false
for Int, Item in pairs(workspace:GetChildren()) do -- Assuming the part is in the Workspace
if Item:IsA("BasePart") and Item["Name"] == "Part" then -- Checking if its a part and has the name "Part"
local Magnitude = (Item["Position"] - HumanoidRootPart["Position"])["magnitude"]
if Magnitude <= 10 then -- Checking whether the HumanoidRootPart is less than the given Range
local Position = CurrentCamera:WorldToScreenPoint(Item["Position"])
Frame["Visible"] = true -- Making the GUI visible
Frame["Position"] = UDim2.new(0, Position["X"], 0, Position["Y"], 0)
end
end
end
print(Frame["Visible"])
end)
Alternative:
I don’t know if this is an actual issue but if you want to still try to make your script work, you can use a ScreenGui.
Example:
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local CurrentCamera = Workspace["CurrentCamera"]
local Frame = script["Parent"]
local LocalPlayer = game:GetService("Players")["LocalPlayer"]
local HumanoidRootPart = LocalPlayer["Character"]:WaitForChild("HumanoidRootPart")
RunService["RenderStepped"]:Connect(function()
Frame["Visible"] = false
for Int, Item in pairs(workspace:GetChildren()) do
if Item:IsA("BasePart") and Item["Name"] == "Part" then
local Magnitude = (Item["Position"] - HumanoidRootPart["Position"])["magnitude"]
if Magnitude <= 10 then -- 10 is the range
local Position = CurrentCamera:WorldToScreenPoint(Item["Position"])
Frame["Visible"] = true
Frame["Position"] = UDim2.new(0, Position["X"], 0, Position["Y"], 0)
end
end
end
end)