Alright I’m basically at a roadblock, i have tried countless ways to do this but honestly i don’t know what to do anymore. I’m trying to kick out a player of a table when they die, however I really don’t know what the issue is.
I tried looking at devforum posts, youtube tutorials and other sites however I haven’t found a solution
i’ll past in the full script below
local rlenght = 10
local ilenght = 5
local rval = game.ReplicatedStorage.round
local status = game.ReplicatedStorage.textstatus
local plrs = {}
rval.Changed:Connect(function()
if rval.Value == true then
warn("true")
local maps = game.ReplicatedStorage.maps:GetChildren()
local random = math.random(1, #maps)
local map = maps[random]:Clone()
local spawns = map:WaitForChild("spawns")
local availablespawns = spawns:GetChildren()
warn(map)
map.Parent = workspace.loadedmaps
for _, player in pairs(game.Players:GetChildren()) do
local tag = player:FindFirstChild("statsfolder").GameTag
tag = true
if tag == true then
table.insert(plrs,player)
else
table.remove(plrs,player)
end
end
for i, player in pairs(plrs) do
local tag = player:FindFirstChild("statsfolder").GameTag
if player and tag == true then
local character = player.Character
if character then
character:FindFirstChild("HumanoidRootPart").CFrame = availablespawns[1].CFrame + Vector3.new(0,10,0)
table.remove(availablespawns,1)
else
if not player then
table.remove(plrs, i)
end
end
end
end
end
if rval.Value == false then
warn("false")
for i,v in pairs(workspace.loadedmaps:GetChildren()) do
wait(.1)
v:Destroy()
end
end
end)
local function round()
while wait() do
for i = ilenght, 0, -1 do
rval.Value = false
wait(1)
status.Value = "Intermission"..i
end
for i = rlenght, 0, -1 do
rval.Value = true
wait(1)
status.Value = "start "..i
for x, player in pairs(game.Players:GetChildren()) do
if player then
local character = player.Character
if character then
local tag = player:FindFirstChild("statsfolder").GameTag
if tag == false then
table.remove(plrs, x)
end
else
table.remove(plrs, x)
end
end
end
if #plrs == 0 then
for i, player in pairs(game.Players:GetChildren()) do
table.remove(plrs, i)
end
warn("end")
break
elseif #plrs == 1 then
status.Value = #plrs[1].Name
for i, player in pairs(game.Players:GetChildren()) do
table.remove(plrs, i)
end
warn("win")
break
end
end
end
end
spawn(round)
yes i know the code is messy, i have put in some things that i have forgotten to remove that eventually became a part of it
You can connect a function to every player when they join which will fire when they die, then check if they are in the table and remove them from it:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
local intable = table.find(plrtable,player)
if not intable then return end
table.remove(plrtable,intable)
end)
end)
end)
Also, when removing a player from a table you have to specify the index on which they are and not the player itself. For example: table.remove(table,1) will remove the value at first index of a table, which will be the first player added to the table. If you want to get the position of any player in the table (or if they are not in it) you can use table.find() where first argument is the table you are searching in, and second is the value you are searching for (the player for example). table.find() returns index in the table of a value you are searching for (if it finds it), or nil if the value isnt in the table. So table.remove(table,table.find(table,player)) will remove the player from the table (if the player is in the table), but will error if player isn’t in the table so its best to first check if player is in the table and then remove them:
local intable = table.find(yourtable,player) --check if player is in table
if intable then --check if intable isn't nil
table.remove(yourtable,intable) --remove player from the table
end
put a REMOTE event called “Died” in replicated storage,
use a localscript in starterscripts
local storage = game:GetService("ReplicatedStorage")
game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
storage.Died:FireServer()
end)
then on the server,
local storage = game:GetService("ReplicatedStorage")
storage.Died.OnServerEvent:Connect(function(player)
print("stuff")
-- use player if you need (references to player that sent it)
end)