How could i remove a player from a Table when he died or disconnected?
Asked by
6 years ago Edited 6 years ago
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
2 | print ( "Everybody died" ) |
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
01 | game:GetService( "Players" ).PlayerAdded:Connect( function (player) |
02 | player.CharacterAdded:Connect( function (character) |
03 | character:WaitForChild( "Humanoid" ).Died:Connect( function () |
05 | for i, v in pairs (_G.Districts) do |
06 | if v ~ = player.Name then |
07 | table.insert(Update, 1 ,v) |
15 | game:GetService( "Players" ).PlayerRemoving:Connect( function (player) |
18 | for i, v in pairs (_G.Districts) do |
19 | if v ~ = player.Name then |
20 | table.insert(Update, 1 ,v) |
MAIN SCRIPT
02 | local Players = game:GetService( "Players" ) |
03 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
06 | local Remotes = ReplicatedStorage:WaitForChild( "Remotes" ) |
07 | local Names = Remotes:WaitForChild( "Names" ) |
08 | local Round = Remotes:WaitForChild( "Round" ) |
11 | local Tributspawn = workspace:WaitForChild( "Tribut" ) |
14 | function Shuffle(Table) |
16 | for i = Size, 1 , - 1 do |
17 | local RandomObject = Random.new():NextInteger( 1 , Size) |
18 | Table [ i ] , Table [ RandomObject ] = Table [ RandomObject ] , Table [ i ] |
27 | local Players = (Shuffle(game:GetService( "Players" ):GetPlayers())) |
29 | for i = ( 1 ),(math.ceil(#Players/ 2 )) do |
30 | _G.Districts [ #_G.Districts + 1 ] = { } |
33 | for Player = ( 1 ),(#Players) do |
34 | local DesiredDistrict = (math.ceil(Player/ 2 )) |
35 | table.insert(_G.Districts [ DesiredDistrict ] , Players [ Player ] ) |
36 | Names:FireAllClients(DesiredDistrict,Players [ Player ] ) |
44 | print ( "Everybody died" ) |