local playersNeeded = 2
local num0fPlayers = 0
local sessionData = {}
local function isEnoughPlayers()
if num0fPlayers >= playersNeeded then
print("There are enough players, get ready!")
return true
else
print("Waiting for players")
return false
end
end
local function intermission()
for i=10, 1, -1 do
print("Intermission Ending: ", i)
wait(1)
end
end
local function checkForWinner()
if num0fPlayers == 1 then
for ply, data in pairs(sessionData) do
print("player = ", ply.Name, "won the game!")
data["isPlaying"] = false
data["wins"] = data["wins"] + 1
end
end
end
local function checkIfAnyoneIsPlayer()
for ply, data in pairs(sessionData) do
if data["isPlaying"] then
return true
end
end
return false
end
local function preparePlayers()
local spawns = workspace.GameSpawns:GetChildren()
local i = 1
for ply, data in pairs(sessionData) do
data["isPlaying"] = true
ply.Character.HumanoidRootPart.CFrame = CFrame.new(spawns[i].Position)+Vector3.new(0, 5, 0)
i = i+1
end
end
local function playGame()
local stillPlaying = true
preparePlayers()
while stillPlaying do
for ply, data in pairs(sessionData) do
if data["isPlaying"] then
print("player = ", ply.Name, " go ahead and roll")
checkForWinner()
stillPlaying = checkIfAnyoneIsPlayer()
wait(1)
end
end
wait(1)
end
preparePlayers()
end
local function gameLoop()
while true do
wait(1)
if isEnoughPlayers() then
intermission()
playGame()
end
end
end
spawn(gameLoop)
local function addChar(char)
local player = game.Players:GetPlayerFromCharacter(char)
sessionData[player]["isPlaying"] = false
end
local function removePlayer(player)
sessionData[player] = { isPlaying=false, wins=0}
num0fPlayers = num0fPlayers
player.CharacterAdded:Connect(addChar)
end
local function removePlayer(player)
end
game.Players.PlayerAdded:Connect(addPlayer)
game.Players.PlayerRemoving:Connect(removePlayer)
Woah there buddy, maybe use ``` in-between your text so we don’t just see messy unformatted code? Also any errors in the output when you try to play it?
First off, remove the empty local function as I think that’s calling a nil value.
Second game.Players.PlayerAdded:Connect(addPlayer) is a unknown value, you will have to define that.
Third try running this script in StarterCharScripts:
local Player = game.Players.LocalPlayer
while #game.Players:GetPlayers() < 2 do--While we have less then 2 players this func will fire
local gui = Player.PlayerGui
local UI1 = gui:FindFirstChild("Under2UI") --Switch to your UI name
print("Not enough players were found. At least 2 players are needed to start a round.")--Notify output we don't have enough players.
UI1.Enabled = true
wait(20) --Check for playercount every 20 second(keep at least 1 wait in here or you will die of lag)
end
function tp()
local players = game.Players:GetPlayers()
for i = 1,#players do
players[i].Character.HumanoidRootPart.CFrame = game.Workspace.Baseplate.CFrame + Vector3.new(65, 0.5, -324) --Teleport all players to this location
wait(60) --Intermissions
end
end
tp()--Call TP if there is more then 2 players
Its a basic version of what you are trying to do, you would just have to add the code for winning into this.
I believe your talking about step 2?
This part of your script:
Isn’t defined. You will have to define it or it try’s to connect when nil is fired.
If your talking about the script I sent, it’s just a more basic version of what your trying to do not your script that I edited or something.