I'm wondering the best way to check the amount of players remaining in a round. If I do:
hum.Died:connect(function()
alive[player][1] = false
checkAlive()
end)
then I'm scared the two players will tie and the game will end twice.. or is the best option to add a game ending debounce?? Here's my script so far:
--// Services
local ws = game:GetService("Workspace");
local pls = game:GetService("Players");
local repstr = game:GetService("ReplicatedStorage");
local ss = game:GetService("ServerStorage");
--// References
local gameFolder = Instance.new("Folder", ws)
gameFolder.Name = ".GameSettings" -- Has . in the beginning because hopefully the player GameSettings doesn't join lol
local alive = {} -- alive[player] = {PLAYING(TRUE/FALSE, KILLS/POINTS}
local playing = {} -- playing[player] = true/false
--// Variables
local vars = {"GameState", "Intermission"}
local varInfo = { -- Value type, default value
["GameState"] = {"StringValue", ""};
["Intermission"] = {"IntValue", 0}
};
for i = 1,#vars do
local newValue = Instance.new(varInfo[vars[i]][1], gameFolder)
newValue.Value = varInfo[vars[i]][2]
end
--// Game functions (intermission, begin, end, etc)
function checkAlive()
a = 0
for _,player in pairs(pls:GetPlayers()) do
pcall(function() -- just incase the player isnt even in the dictionary
if alive[player][1] == true then
a = a+1
end)
end
return a
end
function intermission(startTime, gameMode) -- ignore this im finishing this later on cuz ez
local timerValue = gameFolder:WaitForChild("Intermission")
end
function beginGame(gameMode)
for _,player in pairs(pls:GetPlayers()) do
if playing[player] == true then -- if player is marked as playing, then let him join!!
alive[player] = {true, 0}
player:LoadCharacter()
repeat wait() until player.Character
local hum = player.Character:WaitForChild("Humanoid")
hum.Died:connect(function()
alive[player][1] = false
checkAlive() -- can do the ending after this blablabla
end)
end
end
end
