Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago
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

Log in to vote
2
Answered by 9 years ago
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.

Ad

Answer this question