I'm trying to make a minigame game and the way I want it to work is by putting all players into a table and then removing them when they die or leave. Currently I'm working on the die part, but it's not working. Everything else seems to work just fine on its own.
local maps = game.ServerStorage.maps:GetChildren()
local storage = game.Workspace.place
local clock = 30 --game starts quickly
local Players = game:GetService("Players")
local plrs = {}
function mapchange()
print ("bruh")
storage:ClearAllChildren() --clear map
wait(10) -- intermission
local random_map = maps[math.random(1,#maps)]
random_map:Clone().Parent = storage -- new map loaded
wait(1)
for i,v in pairs(game.Workspace:GetChildren()) do
if v:findFirstChild("Humanoid") then
local rx = math.random(-20,20)
local rz = math.random(-20,20)
if v:findFirstChild("HumanoidRootPart") then
v.HumanoidRootPart.Position = Vector3.new(rx, 79.5, rz) --tp all players inside
end
end
end
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
table.insert(plrs, v) --living players all added to list
end
print(#plrs) --number of living players
--THIS PART BELOW WONT WORK
for i,v in pairs(Players:GetChildren()) do
v.Character.Humanoid.Died:Connect(function()
print("git rekt" .. v.Character.Name) --this prints correctly
local deadguy = v
for i, v in pairs(plrs) do
if v == deadguy then
table.remove(plrs, i)
end
end
end)
--if everyone finna die but one person (or not one person)
--this also works when I test with one player
if #plrs == 1 then
print("one left")
mapchange()
print (table.concat(plrs))
plrs = {}
elseif #plrs == 0 then
mapchange()
end
end
end
--2 minutes per round, this timer makes sure of that
while true do
if clock ~= 0 then
wait(1)
clock = clock - 1
if clock == 0 then
clock = 120
wait(1)
mapchange()
end
end
end

1 comment
Also, no errors are printed. Nothing happens at all.