Hello everyone, so as I was working on my game project when I stumbled on a problem. So there’s this issue where after the first round ends, starts a new round, then teleports the players, and if I reset one of the players it does not end the function and called the player still alive the winner. Instead, If I reset the player that’s still alive, the previous player that won the previous round would get the win. Why is that? I am very confused right now.
It occurs in this module function right here:
function moduleFunction.CheckWinner(parent)
if #playersInRound > 1 then
while #playersInRound >= 2 do
parent.Value = "Game in progress"
wait()
if #playersInRound == 1 then
local player = playersInRound[1]
print("The Winner is: " .. player.Name)
parent.Value = player.Name .. " has won this round!"
wait(5)
elseif #playersInRound == 0 then
print("There was not a single winner.")
parent.Value = "No one won this round"
wait(5)
end
end
end
end
I would appreciate it if some would help thanks.
If you would like to see the whole module please ask!
I dont know how to completely do something like this, but If you made a table or if you havent, you should make one and when a player dies or loses make it so they get removed from the table
local moduleFunction = {}
local playersInRound = {}
local connections = {}
local playerInfo = {
AFK = false;
InRound = false
}
function moduleFunction.ReturnPlayersInfo()
return playerInfo
end
---------------------------------------------------------------------------------------------------------------------------
-- // Game Functions \\ --
---------------------------------------------------------------------------------------------------------------------------
function moduleFunction.AddValue()
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local isPlaying = Instance.new("BoolValue")
isPlaying .Name = "IsPlaying"
isPlaying .Parent = player
end)
end
function moduleFunction.AddPlayer(player)
if player:IsA("Player") then
if playerInfo.AFK == false then
playerInfo.InRound = true
print(player)
table.insert(playersInRound, player)
connections[player.Name] = player.Character.Humanoid.Died:Connect(function()
table.remove(playersInRound, table.find(playersInRound, player))
end)
elseif playerInfo.AFK == true then
warn("Player is afk. Was not added to the list")
playerInfo.InRound = false
end
end
for i, player in pairs (playersInRound) do
print(player)
wait()
end
end
function moduleFunction.PlayerLeft()
connections["Removing"] = game.Players.PlayerRemoving:Connect(function(player)
local playerLeft = table.find(playersInRound, player)
if playerLeft then
table.remove(playersInRound, playerLeft)
playerInfo.InRound = false
end
end)
end
function moduleFunction.CheckWinner(parent)
if #playersInRound > 1 then
while #playersInRound >= 2 do
parent.Value = "Game in progress"
wait()
if #playersInRound == 1 then
local player = playersInRound[1]
print("The Winner is: " .. player.Name)
parent.Value = player.Name .. " has won this round!"
wait(5)
elseif #playersInRound == 0 then
print("There was not a single winner.")
parent.Value = "No one won this round"
wait(5)
end
end
end
end
function moduleFunction.RemovePlayer()
for _, connection in pairs(connections) do
connection:Disconnect()
wait()
end
for _, player in pairs(playersInRound)do
player:LoadCharacter()
print(player)
wait()
end
playerInfo.InRound = false
end
return moduleFunction
Ignore the first function, I didn’t use it in any scripts
That’s not the exact issue tho. The issue is that whoever wins the first round for some reason wins all the rounds right after that even if that player died.