I have this script where it would loop. It works in test mode, however online, it throws an error saying PlayerGui is not a valid member of Script.
Would anyone be able to help? Thanks
for _,a in pairs (game.Players:GetChildren()) do
if not (a.PlayerGui:findFirstChild("Main")) then
-EDIT- Here is the full script that I am using this in. It prints the line 3 but not the line 7 which means it's not passing. This is also the edited code with the loop searching for PlayerGui, before on line 6, it would give an error saying PlayerGui is not a valid member of Script. So basically, it's not finding PlayerGui in the player.
wait(5)
while wait(10) do
print("easyJet Allocated Seating: Checking players. /Script: CheckPlayer/")
for _,a in pairs (game.Players:GetChildren()) do
repeat wait() until a:findFirstChild("PlayerGui")
if not (a.PlayerGui:findFirstChild("Main")) then
print("easyJet Allocated Seating: Given booking GUI to "..a.Name..". /Script: CheckPlayer/")
local bookedvalue = script.Parent.Booked
local newvalue = bookedvalue:clone()
newvalue.Parent = a
local newscript = script.Parent.AllocatedSeating:Clone()
newscript.Parent = a.PlayerGui
newscript.Disabled = false
local gui = script.Parent.Main
local newgui = gui:clone()
for _,b in pairs (game.Workspace:GetChildren()) do
if b:IsA("Model") then
local asvalue = b:findFirstChild("AllocatedSeating")
if asvalue then
if b.Name == "Model" then
plane = b:findFirstChild("easyJetAirbus A319")
else
plane = b
end
end
end
end
newgui.Parent = a.PlayerGui
newgui.Adornee = plane.PlaneKit.Plane.AllocatedSeatingBoard
newgui.Enabled = true
end
end
end

3 comments
I would suggest using :GetPlayers() to be on the safe side in case there is something stored in players that isn't a player and that is erroring it, you may also want to add a check to see if "a" actually has a playergui then run that
Is it doing this at a specific time or whenever someone enters the game?
When I insert the model into the game, this script runs.