So this is kinda complicated to explain but im just gonna give you my whole Script so you might be able to understand what i did here. So i got a District System going like the Hunger games and i know how to check, how many Players are alive. But my major problem is to make a "Death/Leave" Script so it updates the Table when a player dies or disconnects. The Problem here is that If i want to check how many Players are alive i use
if #Players == 0 then
print("Everybody died")
break
end
which is the only way i believe in this code. If i want to use _G.Districts it wont work. #Players gives me an Number of how many are in the table i believe.
So Is there a better way to write this script? Is there even a way to get my Death/Leave script working? Im so confused by now and my head hurts.
Here is my Whole Script + my attempt to write a Death and Leave Script. Basicly what i wanna know is how to make a death and leave script and make it comportable with mine. Thanks alot if you're still reading <3
DEATH AND LEAVE SCRIPT
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
local Update = {}
for i, v in pairs(_G.Districts) do
if v ~= player.Name then
table.insert(Update,1,v)
end
end
_G.Districts = Update
end)
end)
end)
game:GetService("Players").PlayerRemoving:Connect(function(player)
local Update = {}
for i, v in pairs(_G.Districts) do
if v ~= player.Name then
table.insert(Update,1,v)
end
end
_G.Districts = Update
end)
MAIN SCRIPT
--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Remotes
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Names = Remotes:WaitForChild("Names")
local Round = Remotes:WaitForChild("Round")
--//Variables
local Tributspawn = workspace:WaitForChild("Tribut")
--//Functions
function Shuffle(Table)
local Size = (#Table)
for i = Size, 1, -1 do
local RandomObject = Random.new():NextInteger(1, Size)
Table[i], Table[RandomObject] = Table[RandomObject], Table[i]
end
return Table
end
--//Main
while true do
wait(3)
_G.Districts = {}
local Players = (Shuffle(game:GetService("Players"):GetPlayers()))
for i = (1),(math.ceil(#Players/2)) do
_G.Districts[#_G.Districts + 1] = {}
end
for Player = (1),(#Players) do
local DesiredDistrict = (math.ceil(Player/2))
table.insert(_G.Districts[DesiredDistrict], Players[Player])
Names:FireAllClients(DesiredDistrict,Players[Player])
wait(2)
end
print("Round starts")
for t = 10,0,-1 do
wait(1)
print(t)
if #Players == 0 then
print("Everybody died")
break
end
end
end

2 comments
I see you did a lot of work there, sadly my knowledge is not good enough for this kind of code. I never invented time into ModuleScripts etc also sadly i dont know how to make it comportable with mine. Still you did a great job, i tested it in a new game and it works well :)
You can do a lot of things with modules. A module script will only run once upon using the function require. It helps lead to better code design by reusing code and making for better code strucures ie one thing does one task.