I am making a sandbox game in roblox, one where anyone can make their own obby. I have a Billboard Gui in StarterGUI that shows up whenever someone clicks an object. When i click the object, it says that BillboardGUI is not a valid member of PlayerGui. The game works perfectly when i test it in studio, but not when i play it in Roblox Player. I have no idea what's going on, could someone please help me?
Edit:
The script that i was using was in the part that was clicked, and this is the script:
part = script.Parent.Parent part.ClickDetector.MouseClick:connect(function(player) local billboard = player.PlayerGui:WaitForChild("BillboardGui") billboard.Adornee = part if billboard.Enabled == true then billboard.Enabled = false else billboard.Enabled = true end end)
It's usually because you didn't wait for the BillboardGui to "exist". You see, scripts start even earlier before some things even exist (load into the game).
Use a WaitForChild()
.
For example, like this:
local starterGui = script.Parent local billBoardGui = starterGui:WaitForChild("BillboardGui") -- the rest of the code goes here, use the "billBoardGui" variable. Or whatever you called it. billBoardGui:Destroy() -- this will wait for the BillboardGui to load or exist, then destroy the BillboardGui. An example..
Edit:
Try this.
part = script.Parent.Parent part.ClickDetector.MouseClick:connect(function(player) local playerGui = player:FindFirstChild("PlayerGui") local billboard = playerGui:WaitForChild("BillboardGui") billboard.Parent = part if billboard.Enabled == true then billboard.Enabled = false else billboard.Enabled = true end end)
Though, I think this may only work once.
Tiny edit on Xrp200's code:
part = script.Parent.Parent part.ClickDetector.MouseClick:connect(function(player) local playerGui = player:FindFirstChild("PlayerGui") local billboard = playerGui:WaitForChild("BillboardGui", 50) billboard.Parent = part if billboard.Enabled == true then billboard.Enabled = false else billboard.Enabled = true end end)
We have no specified the time argument of WaitForChild. With no argument, it waits a super tiny amount of time. With this instead, it waits for it for a long time (50 secs). In the case it's not working, try this:
part = script.Parent.Parent part.ClickDetector.MouseClick:connect(function(player) local playerGui = player:FindFirstChild("PlayerGui") local billboard = playerGui:FindFirstChild("BillboardGui", 50) if billboard == nil then local billboard = playerGui:WaitForChild("BillboardGui", 50) end billboard.Parent = part if billboard.Enabled == true then billboard.Enabled = false else billboard.Enabled = true end end)
This other code will check if the billboard exists. If it doesn't, it will wait until it is created for more time(50 secs).