Hello, I’m trying to figure out how to make a round system in Roblox. The problem is it only teleports one player to the match at a time. Heres an example to better visualize whats happening:
Suppose there are 2 players, A and B both in the lobby.
- A gets teleported to the match, B is still in lobby
- A comes back to the lobby
- B gets teleported to the match, A is still in lobby
- B comes back to the lobby
and it just contines like that.
local Players = game.Players
local fill = require(script:WaitForChild("LineFiller"))
local functions = require(game.ReplicatedStorage:WaitForChild("Functions"))
--local RoundInProgress, Winners = require(game.ReplicatedStorage:WaitForChild("Round"))
local RoundInProgress = false
local Intermission = 3 --Change to 20 when ready
local MaxPlayers = 0 --Change to 4 when ready
local RoundTime = 3 --Change to 120 when ready
local music = game.SoundService:WaitForChild("GameMusic")
local workspaceMaps = workspace.Maps:GetChildren()
local Winners = {}
local Maps = {}
local TimeLeft = script.TimeLeft
for _, map in pairs(workspaceMaps) do
if map.Name ~= "Intro" then
table.insert(Maps, map)
end
end
while true do
if #Players:GetPlayers() > MaxPlayers then
for index, player in pairs(Players:GetPlayers()) do
local char = player.Character or player.CharacterAdded:Wait()
--Player Values
local inIntro = player.PlayerValues:WaitForChild("isInIntroSequence")
local inSelection = player.PlayerValues:WaitForChild("isInCharacterSelection")
local Spawned = player.PlayerValues:WaitForChild("SpawnedIn")
local inRound = player.PlayerValues:WaitForChild("inRound") --might not need
local lost = player.PlayerValues:WaitForChild("lost") --might not need
local canDash = player.PlayerActionValues:WaitForChild("CanDash")
local canUseJutsu = player.PlayerActionValues:WaitForChild("canUseJutsu")
local CanRun = player.PlayerActionValues:WaitForChild("CanRun")
--Gui Variables
local gui = player:WaitForChild("PlayerGui"):WaitForChild("Gamegui")
local winnergui = player:WaitForChild("PlayerGui"):WaitForChild("Winner").WFrame
local mapSelected = gui.MapSelected.MapName
local timeRemaning = gui.TimeFrame.Time
local winnerName = winnergui.WinnerName.Num
local kills = winnergui.Kills.Num
local rank = winnergui.Rank.Num
local wins = winnergui.Wins.Num
local white = winnergui.Parent.white
--Other Variables
local currentMap = nil
local combat = player.Backpack.CombatHandler
if Spawned.Value == true and RoundInProgress == false then
table.insert(Winners, player)
canDash.Value = false
canUseJutsu.Value = false
char.Humanoid.WalkSpeed = 16
char.Humanoid.JumpPower = 50
CanRun.Value = true
combat.Disabled = true
fill(timeRemaning, "INTERMISSION: ")
for i = Intermission, 0, -1 do
timeRemaning.Text = "INTERMISSION: "..i
wait(1)
end
RoundInProgress = true
currentMap = Maps[math.random(1, #Maps)]
local spawns = currentMap.SPAWNS:GetChildren()
local name = player.Name
local check = workspace:FindFirstChild(name)
if check then
local checkHum = check:FindFirstChild("Humanoid")
if checkHum then
player.Character:MoveTo(spawns[index].Position)
checkHum.WalkSpeed = 0
checkHum.JumpPower = 0
CanRun.Value = false
canDash.Value = false
combat.Disabled = true
end
end
fill(mapSelected, currentMap.Name)
for i = 3, 1, -1 do
timeRemaning.Text = i
wait(1)
end
timeRemaning.Text = "GO!"
char.Humanoid.WalkSpeed = 16
canDash.Value = true
canUseJutsu.Value = true
CanRun.Value = true
char.Humanoid.JumpPower = 50
combat.Disabled = false
char.Humanoid.Died:Connect(function()
table.remove(Winners, index)
print(player.Name .. " has lost")
end)
wait(1)
for i = RoundTime, 1, -1 do
timeRemaning.Text = "Time Left: "..i
TimeLeft.Value = i
wait(1)
end
RoundInProgress = false
char.Humanoid.WalkSpeed = 0
canDash.Value = false
canUseJutsu.Value = false
char.Humanoid.JumpPower = 0
CanRun.Value = false
combat.Disabled = true
fill(timeRemaning, "Time up!")
wait(1)
fill(timeRemaning, "Displaying Winners")
wait(1)
if next(Winners) ~= nil and player then
gui.Enabled = false
winnergui.Parent.Enabled = true
gui.Parent.CharecterGui.Enabled = false
local line = 1
print("Number of winners: "..#Winners)
while line <= #Winners do
fill(winnerName, Winners[line].Name)
print(line, Winners[line].Name)
line = line + 1
wait(2.5)
end
end
for i, player in next, Winners do
table.remove(Winners, i)
print("resetting")
end
gui.Enabled = true
winnergui.Parent.Enabled = false
gui.Parent.CharecterGui.Enabled = true
fill(timeRemaning, "Congrats Everyone!")
wait(1)
char:MoveTo(workspace.Lobby.SpawnLocation.Position)
RoundInProgress = false
elseif Spawned.Value == true and RoundInProgress == true then
fill(mapSelected, currentMap.Name)
end
end
else
for _, player in next, game.Players:GetPlayers() do
local gui = player:WaitForChild("PlayerGui"):WaitForChild("Gamegui")
local timeRemaning = gui.TimeFrame.Time
local mapSelected = gui.MapSelected.MapName
mapSelected.Text = "NONE"
timeRemaning.Text = "Waiting."
wait(0.7)
timeRemaning.Text = "Waiting.."
wait(0.7)
timeRemaning.Text = "Waiting..."
wait(0.7)
end
end
wait()
end
Heres the script if you see anything wrong. Thanks in advance!