Hey guys, I have a script that does various game rounds. As the title explains, it doesn't work as expected.
The following problems were recorded while testing this script:
- Players do not change teams to "Not Playing" after the round
- In the Elimination Round, the Map loads, but players don't spawn.
Could you please help me find and repair this script:
ingame = false
function GetPlayersInTeam(Team)
local TeamColor = Team.TeamColor --Creating a variable storing the color of the team
local PlayersInTeam = 0 --Creating a variable that will store the number of players in the team
for _,Player in pairs(game.Players:GetPlayers()) do --Creating a loop that will go through all the players
if Player.TeamColor == TeamColor then --Checking if the Player's TeamColor is the same as the team's TeamColor
PlayersInTeam = PlayersInTeam + 1 --If it is, adding 1 to the variable we created earlier
end
end
return PlayersInTeam--Returning the amount of players in the team
end
function ChooseTeam()
Players = game.Players:GetPlayers()
for i = 1,#Players do
Players[i].TeamColor = game.Teams.Playing.TeamColor
end
end
function ChooseMap()
Maps = game.Lighting.Maps:GetChildren()
chosen = Maps[math.random(1,#Maps)]:Clone()
chosen.Parent = game.Workspace
end
function Classic()
workspace.Ingame.Value = true
Text = "Round Chosen: Classic"
for i=1,#Text do
game.Workspace.Lobby.Noti.SurfaceGui.TextLabel.Round.Text = Text:sub(1,i)
wait(0.1)
end
ChooseMap()
Map = "Map Chosen: "..chosen.Name
for i=1,#Map do
game.Workspace.Lobby.Noti.SurfaceGui.TextLabel.Map.Text = Map:sub(1,i)
wait(0.1)
end
game.Workspace:WaitForChild(chosen.Name).Name = "Map"
ChooseTeam()
players = game.Players:GetPlayers()
for i=1,#players do
players[i]:LoadCharacter()
end
chosen.During:Play()
game.Workspace.Time.Value = 5*60
game.Players.PlayerAdded:connect(function(player)
if game.Workspace.Time.Value >10 then
player.TeamColor = game.Teams.Playing.TeamColor
wait(0.5)
player:LoadCharacter() end
end)
while wait() do
if game.Workspace.Time.Value == 0 then
workspace.Ingame.Value = false
for i=1,#players do
if game.Players:FindFirstChild(players[i]) then
items = players[i].Backpack:GetChildren()
for b = 1,#items do
if items[b]:IsA("Tool") then
items[b]:Destroy()
end
end
players[i].TeamColor = game.Teams["Not Playing"].TeamColor
wait(0.5)
players[i]:LoadCharacter() end
end
game.Workspace:FindFirstChild("Map"):Destroy()
break
end
end
chosen.During:Stop()
for i = 1,#players do
players[i].TeamColor = game.Teams['Not Playing'].TeamColor
players[i]:LoadCharacter()
end
workspace.End:Play()
wait(6)
while wait() do
if workspace.End.IsPlaying == false then
break
end
end
end
function Elimination()
workspace.Ingame.Value = true
workspace.Elimination.Value = true
Text = "Round Chosen: Elimination"
for i=1,#Text do
game.Workspace.Lobby.Noti.SurfaceGui.TextLabel.Round.Text = Text:sub(1,i)
wait(0.1)
end
ChooseMap()
Map = "Map Chosen: "..chosen.Name
for i=1,#Map do
game.Workspace.Lobby.Noti.SurfaceGui.TextLabel.Map.Text = Map:sub(1,i)
wait(0.1)
end
chosen.During:Play()
game.Workspace:WaitForChild(chosen.Name).Name = "Map"
ChooseTeam()
players = game.Players:GetPlayers()
for i=1,#players do
if players[i] then
players[i]:LoadCharacter()
end
end
game.Workspace.Time.Value = 5*60
while true do
if game.Workspace.Time.Value <= 0 then
workspace.Ingame.Value = false
for i=1,#players do
if game.Players:FindFirstChild(players[i]) then
items = players[i].Backpack:GetChildren()
for b = 1,#items do
if items[b]:IsA("Tool") then
items[b]:Destroy()
end
end
players[i].TeamColor = game.Teams["Not Playing"].TeamColor
wait()
players[i]:LoadCharacter() end
end
game.Workspace:FindFirstChild("Map"):Destroy()
break
elseif GetPlayersInTeam(game.Teams.Playing) == 1 then
workspace.Ingame.Value = false
--Get that remaining player's name
Winner = "No one"
for _,Player in pairs (game.Players:GetPlayers()) do
if Player.TeamColor == game.Teams.Playing.TeamColor then
Winner = Player.Name
end
end
-- Got the player's name. Now to kill the round.
Text = Winner.." Has won the round!"
for i=1,#Text do
game.Workspace.Lobby.Noti.SurfaceGui.TextLabel.Round.Text = Text:sub(1,i)
wait(0.1)
end
for i,Player in pairs (game.Players:GetPlayers()) do
Player.TeamColor = game.Teams["Not Playing"].TeamColor
Player:LoadCharacter()
end
game.Workspace.Time.Value = 0
end
end
chosen.During:Stop()
workspace.Elimination.Value = false
workspace.End:Play()
wait(6)
while wait() do
if workspace.End.IsPlaying == false then
break
end
end
end
function ChooseRound()
Round = {"Classic","Elimination"}
Rchosen = math.random(1,#Round)
if Rchosen == 1 and game.Players.NumPlayers >= 4 then Classic()
elseif Rchosen == 2 and game.Players.NumPlayers >=2 then Elimination()
end
end
while wait(10) do
if game.Players.NumPlayers >= 4 then
ChooseRound()
else
a = game.Workspace.Time.Tme
if game.Players.NumPlayers == 3 then
Text = "Waiting for 1 more player"
for i=1,#Text do
a.Value = Text:sub(1,i)
wait(0.1)
end
else
Text = "Waiting for "..(4-game.Players.NumPlayers).." More Players"
for i=1,#Text do
a.Value = Text:sub(1,i)
wait(0.1)
end
end
wait(1.9)
a.Value = ""
end
end

3 comments
A Question to the Admin that put up that note: How is the question irrelevant to the problem?
You're just asking why the script isn't working. This site is to help people who can analyze what's going wrong with their scripts, but can't fix them, fix their scripts. So, for us to be able to help you, instead of having us go through a 183 line script, please just post the bit of code that isn't working.
@fahmisack123 Your question is irrelevant to your problem because you can put any code in the question and your title question will match the problem. This doesn't help anyone else that might have a similar problem to your own.