How to subtract and add to a table




local tabla = {}

game.Players.PlayerAdded:Connect(function(plr)
	plr:LoadCharacter()	
	plr.CharacterAdded:Connect(function(megustalapj)
	table.insert(tabla,plr.Name)
	for i,obtenerjugador in pairs(tabla) do
		if obtenerjugador == plr.Name then
			print(tabla)
			wait(3)
			local char = plr.Character
			char.Humanoid.Died:Connect(function(died)
				table.remove(tabla,plr.Name)
				wait(2)
				print(tabla.."tabla eliminada")
			end)
		end
		
	end
end)
end)

I want the player to remain on a table when he is alive but when he dies I take him out of the table and so on, please help me and if you don’t know, just give your opinion, it doesn’t matter if you think your opinion is stupid

First, I’m gonna assume the variable names are Spanish. Just a little thing I noticed :laughing:


Anyways, are you getting any errors in the output? At a quick glance everything looks fine and should work.

It tells me that it is a string or something like that

Can you show me the error, please?

table.remove requires the index value as the second parameter rather than the string value of the name. Try the following.

table.remove(tabla, table.find(tabla, plr.Name))
2 Likes

image
change the script:

local tabla = {}

game.Players.PlayerAdded:Connect(function(plr)
	plr:LoadCharacter()	
	plr.CharacterAdded:Connect(function(megustalapj)
	table.insert(tabla,plr.Name)
	for i,obtenerjugador in pairs(tabla) do
		if obtenerjugador == plr.Name then
			print(tabla)
			wait(3)
			local char = plr.Character
			char.Humanoid.Died:Connect(function(died)
				table.remove(tabla,table.find(plr.Name))
				wait(2)
				print(tabla.."tabla eliminada")
			end)
		end
		
	end
end)
end)

Change this to print(plr.Name.."tabla eliminada")

I’m sorry, I thought that the error was at the time of subtracting, not in the print

Hey, really, your answer was very useful, but I need another favor, how would I know if the player’s name is in a table? Please, if you want, give me several options that you know of, please, I beg you. I need your help.

local PlayerName = "wsyong11"

if table.find(tabla, PlayerName) then
    print("Player in table")
end
2 Likes

hey thanks but by chance you don’t know how to refer to a table from a different script than the one that created the table?

maybe this will help you

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.