I’m trying to get BillboardGui’s that are parented to the closest door, to become visible when I’m within the maximum distance. But I keep getting this error for some reason and I’m stuck trying to figure out how to solve this.
--// OUTPUT ERROR
03:37:53.238 - RunService:fireRenderStepEarlyFunctions unexpected error while invoking callback: ReplicatedStorage.Assets.Modules.GuiService:20: bad argument #2 to '?' (Vector3 expected, got nil)
03:37:53.252 - ReplicatedStorage.Assets.Modules.GuiService:20: bad argument #2 to '?' (Vector3 expected, got nil)
--// MODULE (SERVER & CLIENT).
--// Variables
local GuiService = {}
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local Doors = game.Workspace.World.Doors:GetDescendants()
local MaxDistance = 15
function GuiService:EnableNearestBillboardGui(Part)
for index, descendant in pairs(Part) do
local Distance = (Root.Position - Part.Position).magnitude
if Distance < MaxDistance then
local Billboard = Part:FindFirstChildOfClass("BillboardGui")
if Billboard then
Billboard.Enabled = true
else
Billboard.Disabled = true
end
end
end
end
function GuiService:Initialize()
RunService:BindToRenderStep("BillboardGuiBinding", 1, function()
GuiService:EnableNearestBillboardGui(Doors)
end)
end
return GuiService
--// CLIENT
local ReplicatedStorage = game.ReplicatedStorage.Assets.Modules
local GuiService = require(ReplicatedStorage.GuiService)
wait(10)
GuiService:Initialize()