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

How to make all players play at the same time?

Asked by 3 years ago

How do I make the script so that when a server is created the spectating value is running at the same time because it seemed like if a player was waiting and a new player joined the old player would be in the game before the new player?

local Players = game:GetService("Players")

local spectating = true
local inGame = false
Players.PlayerAdded:Connect(function(player)
    local debounce = Instance.new("BoolValue", player)
    debounce.Name = "GameDebounce"
    while true do
        wait()
        if spectating == true and inGame == false and not debounce.Value then
            player.Team = game.Teams.Spectators
            print("Player is spectating")
            wait(30)
            print("Starting Game")
            spectating = false
            inGame = true
            debounce.Value = false
        elseif spectating == false and inGame == true and not debounce.Value then
            player.Team = game.Teams.Players
            print("Game has started")
            local char = player.Character or player.CharacterAdded:Wait()
            char:SetPrimaryPartCFrame(CFrame.new(Vector3.new(-8.92, -2.17, 27.27)))
            debounce.Value = true
        end
    end
end)

Answer this question