So its a hunger games kinda like script. It has a working District system etc. its very simple for now.
I have a 10 second round time for testing purposes and i know how to check how many Players are left in the table.
How would i make "leave/Death" Script which removes the Players who leaves/dies from the table? Its kinda hard to understand this script ( atleast it was for me until now) but i would appreacite if somebody could help me out <3
I tried to do an Leave/Death script but its not working out.. here:
--Side Note, i dont even know if i use the correct Variables like _G.Districts (Also this is in a diffrent script).
game:GetService("Players").PlayerAdded:Connect(function(player) -- Death Script
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) --Leave Script
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)
Here is the 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) --This function is for some math stuff regarding the District System
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]) --This is for a Gui which pops up and shows the Playername , Playerdistrict and the Character Image (ignore it)
wait(2)
end
print("Round starts")
for t = 10,0,-1 do
wait(1)
print(t)
print(#Players) --To see how many Players are in the round
if #Players == 0 then --Still has no point to be here until there is no working death/leave script. But if the script is there its then there to check if it works
print("Everybody died")
break
end
end
end

2 comments
unless im miss understanding can't you use table.remove()?
Its not that easy. If it was that easy i wouldt ask here but i guess nobody can solve this :/