I am trying to spawn players in a map after it is chosen and the map, map name and the creator of the map is shown on a gui and if there are less than 2 players in the game, a gui will come up saying "You need more than 2 players to play" But what happens is the map gui stays up and so does the gui which states you need more players. But they are teleported to the map.
local mapInstantiated = false
maps = game.ReplicatedStorage:GetChildren()
game.Players.PlayerAdded:connect(function (player)
if game.Players.NumPlayers >= 2 and mapInstantiated ~= true then
for i, v in pairs(game.StarterGui:GetChildren()) do
if v.Name == "NMP" then
v.Visible = false
end
end
else
for i,v in pairs(game.StarterGui:GetChildren()) do
if v.Name == "NMP" then
v.Visible = true
end
end
end
ranmap = math.random(1, #maps)
wait(1)
chosen = maps[ranmap]
chosenclone = chosen:Clone()
chosenclone.Parent = game.Workspace
if chosenclone.Parent == game.Workspace then
player.PlayerGui.ScreenGui.Frame.Visible = true
player.PlayerGui.ScreenGui.Frame.Map.Visible = true
player.PlayerGui.ScreenGui.Frame.Madeby.Visible = true
player.PlayerGui.ScreenGui.Frame.MapName.Visible = true
end
wait(5)
spawn = chosenclone.SpawnPoint
mapInstantiated = true
wait(5)
for i,v in pairs(game.Players:GetPlayers()) do
name = v.Name
check = v.Character
if check then
checkHumanoid = check:FindFirstChild("Humanoid")
if checkHumanoid then
check:MoveTo(spawn.Position)
end
end
end
end)

2 comments
You're using StarterGui instead of PlayerGui. No changes will be made until the player respawns.
I changed that for everything and now I get an error on line 13 saying: ServerScriptService.Script:13: attempt to index field 'PlayerGui' (a nil value)