I want to make a fully functional round rotation system, (which I have done, and it was working but now it’s not) but there is an error in my code but I cannot fix it
I have tried look on the developer forum but I couldn’t find anything, if you have anything that can help, please lmk!
The error in the code is that once the players teleport, the round just freezes and nothing happens. If you have and questions about what certain things are, I’d be happy to tell you
local intermissionTime = 10
local gameTime = 120
local interval = 4
local colorSwitchTime = 3
local status = script.Status.Value
local spawns = game.Workspace.Map.SpawnParts
local lobbySpawns = game.Workspace.Lobby.LobbyReturns
local parts = game.Workspace.Map.Balls
local players = game:GetService("Players")
local roundRunning = false
local currentMatchType = "Normal"
local colors = {
BrickColor.new(21),
BrickColor.new(24),
BrickColor.new("Sage green"),
BrickColor.new("Baby blue"),
BrickColor.new("Dark indigo"),
BrickColor.new("Bright violet"),
BrickColor.new("Brown"),
BrickColor.new("Lime green")
}
local function changeText(text)
for i, v in pairs(players:GetPlayers()) do
v.PlayerGui.MainGui.CurrentStatus.Text = text
end
end
local function rewards(plr, winsAmt)
plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value + winsAmt
end
local function createAnvil(partPos)
local position = Vector3.new(partPos.Position.X, partPos.Position.Y + 50, partPos.Position.Z)
local anvil = game:GetService("ReplicatedStorage").Anvil:Clone()
anvil.Position = position
anvil.Parent = game.Workspace.InGame
end
local function teleportPlayers(plrChar)
local spwn = spawns:GetChildren()
local selectedSpawn = spwn[math.random(1, #spwn)]
plrChar.HumanoidRootPart.CFrame = selectedSpawn.CFrame
plrChar.Parent = game.Workspace.InGame
end
local function backToLobby(plrChar)
local lobbies = lobbySpawns:GetChildren()
local selected = lobbies[math.random(1, #lobbies)]
plrChar.HumanoidRootPart.CFrame = selected.CFrame
plrChar.Parent = game.Workspace.InLobby
end
local function startRound()
intermissionTime = 10
roundRunning = true
local randomRound = math.random(1, 100)
if randomRound <= 75 then
currentMatchType = "Normal"
else
currentMatchType = "Difficult"
end
for i, part in pairs(parts:GetChildren()) do
part.Transparency = 0
part.CanCollide = true
end
status = "Round starting ("..currentMatchType..")"
for i, char in pairs (game.Workspace.InLobby:GetChildren()) do
teleportPlayers(char)
end
changeText(status)
wait(1.5)
status = "Round Going ("..currentMatchType..")"
changeText(status)
for i, char in pairs (game.Workspace.InLobby:GetChildren()) do
teleportPlayers(char)
end
end
local function endRound()
currentMatchType = "Normal"
for i, part in pairs(parts:GetChildren()) do
part.Transparency = 1
part.CanCollide = false
end
roundRunning = false
for i, char in pairs (game.Workspace.InGame:GetChildren()) do
backToLobby(char)
end
game.Workspace.LowGravBall:Destroy()
local clone = game.ReplicatedStorage.LowGravBall:Clone()
clone.Parent = game.Workspace
status = "Intermission: 10s"
repeat
intermissionTime = intermissionTime - 1
status = "Intermission: "..intermissionTime.."s"
changeText(status)
wait(1)
until intermissionTime == 0
intermissionTime = 10
startRound()
end
local function checkIfOnePlayer()
local characters = game.Workspace.InGame:GetChildren()
if #characters == 1 or #characters == 0 then
return true
else
return "Keep Going"
end
end
local function colorSwitch()
for i, part in pairs(parts:GetChildren()) do
part.Transparency = 0
part.CanCollide = true
end
local brickColor = colors[math.random(1, #colors)]
parts.Parent.CurrentBrickColor.Value = brickColor
for i, part in pairs(parts:GetChildren()) do
part.BrickColor = colors[math.random(1, #colors)]
end
if currentMatchType == "Difficult" then
for i, part in pairs(parts:GetChildren()) do
local dropAnvil = math.random(1, 50)
if dropAnvil >= 40 then
createAnvil(part)
end
end
end
wait(3)
for i, part in pairs(parts:GetChildren()) do
if part.BrickColor ~= brickColor then
part.Transparency = 1
part.CanCollide = false
end
end
wait(interval)
for i, part in pairs(parts:GetChildren()) do
part.Transparency = 0
part.CanCollide = true
end
end
while true do
wait(intermissionTime)
roundRunning = true
wait(2)
while roundRunning == true do
colorSwitch()
local onePlayer = checkIfOnePlayer()
if onePlayer == true then
if onePlayer == true then
endRound()
for i, char in pairs(game.Workspace.InGame:GetChildren()) do
local winner = game.Players:GetPlayerFromCharacter(char)
rewards(winner, 1)
end
break
else
return
end
end
wait(colorSwitchTime)
end
if roundRunning == false then
endRound()
end
end