I'm trying to make a small game by myself and I can't seem to do this part of the code without it giving an error. The error is ServerScriptService.MainScript:18: attempt to index global 'gui' (a nil value). I have the gui in the right place, and it works in solo mode. But in-game and when I run a server in studio with 2 players, it gives this error. I'm currently using this code. I even define what "gui" is. Help?
--Coded by BoostedUp
local maps = game.ServerStorage:WaitForChild("Maps")
local timebomb = game.ServerStorage:WaitForChild("TimeBomb")
function locategui()
for i, player in pairs(game.Players:GetPlayers()) do
gui = player.PlayerGui.MainGui.MainFrame:WaitForChild("MainText")
end
end
while wait(1) do
locategui()
if game.Players.NumPlayers >= 2 then
gui.Text = "Welcome to Time Bomb!"
elseif game.Players.NumPlayers < 2 then
gui.Text = "Need 2 or more players to start!"
end
end

2 comments
Is your game filtering enabled?
No.