- What are you attempting to achieve? (Keep it simple and clear)
- What is the issue? (Keep it simple and clear - Include screenshots/videos/GIFs if possible)
- What solutions have you tried so far? (Have you searched for solutions through the Roblox Wiki yet?)
What I’m trying to achieve, is to simply, remove a value from the table. The table is, called “PlayersConnected” and contains 4 other tables within the table, at the start of the script being set up as:
local PlayersConnected = {{},{},{},{}}
When I run the function to remove the table, I’ve used debugging to try find the error:
local function RemovePlayer(player)
local t = ""
for _, k in pairs(PlayersConnected) do
t = t .. " | "
for i, v in pairs(k) do
t = t .. tostring(v)
end
end
print("Before: " .. t)
for i, tab in pairs(PlayersConnected) do
for j, v in pairs(tab) do
if v == player then
table.remove(PlayersConnected[i],j)
elseif not Players:FindFirstChild(v.Name) then
table.remove(PlayersConnected[i],j)
end
end
end
t = ""
for _, k in pairs(PlayersConnected) do
t = t .. " | "
for i, v in pairs(k) do
t = t .. tostring(v)
end
end
print("After: " .. t)
end
Sorry that this is phrased a bit all over the place, I’ll explain the actual error here and what’s meant to happen. When a player leaves a pad, the name is removed from the list, which works fine with:
if v == player then
table.remove(PlayersConnected[i],j)
elseif not Players:FindFirstChild(v.Name) then
table.remove(PlayersConnected[i],j)
end
The second elseif (i’m aware you can use “or”, swapped for debugging) searches through Players to see if the player is still in the game, and if they aren’t, to run that code section. I’ve confirmed that, if a player isn’t in the game, that section of the if statement runs. I’ve also confirmed that the other if statement (if v == player) runs AND removes the value from the table. However, by printing the full table before and after the function runs, I’ve confirmed that, for some reason, the value isn’t being removed from the table when the player isnt in the server.
I’ve tried a multitude of solutions across 2 -3 days, from changing the script entirely, checking if its updating with print statements, changing it to Player.Name instead of Player for everything related to it, but in my eyes, logically, this piece of code should work if the if statement before it works?
Thanks for reading, if you can’t understand anything/need more details, please ask.