Hello there!
I seem to have a problem with my round system in my game.
What is supposed to happen is when the round ends (This is supposed to be triggered when there is one player left on the ‘Playing’ team), the player is killed and then a round leaderboard GUI shows up with the first place, second place, and third place and gives all three players their respective “Planet Tokens” for their place on the leaderboard.
However, even when there is nobody playing, the round never stops and I can’t seem to figure out what the problem is.
Here is the parts of my main script that deal with the round:
local GameData = game:GetService("ReplicatedStorage"):WaitForChild("GameData")
local Status = GameData.Status
local Settings = {
PlayersNeeded = 3,
TimeBetweenEvents = 15,
RoundInProgress = GameData.RoundInProgress,
Winner = GameData.Winner,
Second = GameData.SecondPlace,
Third = GameData.ThirdPlace,
ShowLeaderboard = GameData.ShowLeaderboard
}
local function CalculatePlayers()
local NumberOfPlayers = #game.Players:GetPlayers()
return NumberOfPlayers
end
while wait() do
if CalculatePlayers() >= Settings.PlayersNeeded then
for i, v in pairs(Map:GetChildren()) do
if v then
v:Destroy()
end
end
local PlayersInGame = {}
local FirstPlace = {}
local SecondPlace = {}
local ThirdPlace = {}
repeat
for i = Settings.TimeBetweenEvents, 1, -1 do
Status.Value = "Next event in "..i
Sounds.CountdownSound:Play()
wait(1)
Sounds.CountdownSound:Stop()
end
if #PlayersInGame >= 1 then
for _, player in pairs(game.Players:GetPlayers()) do
local PT = player:WaitForChild("leaderstats"):FindFirstChild("Planet Tokens")
if #PlayersInGame == 3 then
if table.find(PlayersInGame, player.Name) then
player:WaitForChild("ThirdPlaceContender").Value = true
end
end
if #PlayersInGame == 2 then
if table.find(PlayersInGame, player.Name) then
player:WaitForChild("ThirdPlaceContender").Value = false
player:WaitForChild("SecondPlaceContender").Value = true
end
end
if #PlayersInGame == 1 then
if table.find(PlayersInGame, player.Name) then
player:WaitForChild("SecondPlaceContender").Value = false
player:WaitForChild("Winner").Value = true
table.insert(FirstPlace, player.Name)
Settings.Winner.Value = table.find(FirstPlace, player.Name)
Settings.RoundInProgress = false
Settings.ShowLeaderboard = true
player.Character.Humanoid.Health = 0
if table.find(ThirdPlace, player.Name) then
PT.Value = PT.Value + 5000
end
if table.find(SecondPlace, player.Name) then
PT.Value = PT.Value + 10000
end
if table.find(FirstPlace, player.Name) then
PT.Value = PT.Value + 20000
end
for i, v in pairs(game.Workspace.Debris:GetChildren()) do
if v then
v:Destroy()
end
end
wait(10)
Settings.ShowLeaderboard = false
Settings.Winner.Value = ""
Settings.Second.Value = ""
Settings.Third.Value = ""
for i, v in pairs(FirstPlace) do
if v then
table.remove(PlayersInGame)
end
end
for i, v in pairs(SecondPlace) do
if v then
table.remove(PlayersInGame)
end
end
for i, v in pairs(SecondPlace) do
if v then
table.remove(PlayersInGame)
end
end
end
end
player.Character.Humanoid.Died:Connect(function()
if player.ThirdPlaceContender.Value == true then
for i, v in pairs(PlayersInGame) do
if v == player then
table.remove(PlayersInGame, i)
end
end
table.insert(ThirdPlace, player.Name)
Settings.Third.Value = table.find(ThirdPlace, player.Name)
elseif player.SecondPlaceContender.Value == true then
for i, v in pairs(PlayersInGame) do
if v == player then
table.remove(PlayersInGame, i)
end
end
table.insert(SecondPlace, player.Name)
Settings.Second.Value = table.find(SecondPlace, player.Name)
end
for i, v in pairs(PlayersInGame) do
if v == player then
table.remove(PlayersInGame, i)
end
end
end)
end
wait(3)
else
for i, v in pairs(PlayersInGame) do
table.remove(PlayersInGame, i)
end
end
until Settings.RoundInProgress.Value == false
else
Status.Value = "Game requires more players to start..."
end
end
And here are the scripts inside the leaderboard GUI
--Script that makes leaderboard GUI pop up when round ends
local Frame = script.Parent
local Status = game:GetService("ReplicatedStorage"):WaitForChild("GameData"):FindFirstChild("ShowLeaderboard")
if Status.Value == true then
Frame.Visible = true
elseif Status.Value == false then
Frame.Visible = false
end
Status.Changed:Connect(function()
if Status.Value == true then
Frame.Visible = true
elseif Status.Value == false then
Frame.Visible = false
end
end)
--Script that show who came first/second/third (each text label has a script like this which shows either first, second, or third depending on which text label the script is in.)
local TextLabel = script.Parent
local Status = game:GetService("ReplicatedStorage"):WaitForChild("GameData"):FindFirstChild("Winner")
TextLabel.Text = Status.Value
Status.Changed:Connect(function()
TextLabel.Text = "1st: "..Status.Value.."(20,000 Planet Tokens)"
end)
I am somewhat of a beginner scripter and can get very very confused with advanced stuff like tables or datastores, so I am 90% sure that the problem is something to do with the tables, I just don’t know what it is.
Any help would be appreciated very much!