Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script only works when Testing in studio and doesnt on a Server?

function startgame()
wait()
if game.Players.NumPlayers >= 1 then
	for _, player in pairs(game.Players:GetPlayers()) do
		local message = player.PlayerGui.ScreenGui.TextLabel
        	message.Text = "Getting The Game Ready"
		wait(3)
		local model = game.Lighting.Maps
		local map = model:GetChildren()[math.random(1, #model:GetChildren())]
		message.Text = (map.Name)
		wait(2)
		startgame()
		end
	end
end
startgame()

I don't know why this doesnt work in Server.

Hope you can help, Thanks!

1 answer

✓ Accepted answer
function startgame()
wait()
if game.Players.NumPlayers >= 1 then
    for _, player in pairs(game.Players:GetPlayers()) do
        local message = player.PlayerGui.ScreenGui.TextLabel
            message.Text = "Getting The Game Ready"
        wait(3)
        local model = game.Lighting.Maps
        local map = model:GetChildren()[math.random(1, #model:GetChildren())]
        message.Text = (map.Name)
        wait(2)
        startgame()
        end
    end
end
repeat wait() until game.Players.NumPlayers >= 1 
startgame()

What's happening here is that when you run the function startgame(), it checks, and there is no players. Then nothing. nothing happens. So what we should do is repeat waiting until the number of players is greater then 0, then run the function for the first time.

This discussion is preserved as it was. New answers, comments, and votes are closed.