Table.remove problem

Basically, there is a table (called plrs) that stores every player’s name in it. Every player has three lives and when they reach zero then they die and gets removed from the table. I have tried various methods but each time it does not work. Can somebody please help me and pick out any mistakes I did? Thank you for reading

Here’s the scripts (I know it’s a bit messy sorry about that)

Server Script (called Stats):

game:GetService("ReplicatedStorage"):WaitForChild("ActuallyDead").OnServerEvent:Connect(function()
				if GamesStart.Value == true then
					if character:FindFirstChild("GameTag") then
						character.GameTag:Destroy()
					end
					player.Team = game.Teams["Not Playing"]
					wait(2)
					game.ReplicatedStorage:WaitForChild("SpectateShow"):FireClient(player, true)
					game.ReplicatedStorage:WaitForChild("EquippedShow"):FireClient(player, true)
					game.ReplicatedStorage:WaitForChild("Lives"):FireClient(player, false)
					game.ReplicatedStorage:WaitForChild("LivesButThisTimeItWillWok"):FireClient(player, player)
				end
			end)

Don’t bother with the other code, just focus on “LivesButThisTimeItWillWok” remote event (strange name I know)

Local script (called “Lives”):

game:GetService("ReplicatedStorage"):WaitForChild("LivesButThisTimeItWillWok").OnClientEvent:Connect(function(player)
    game:GetService("ReplicatedStorage"):WaitForChild("tablePlrs"):FireServer(player)
end)

Server script (called “MainScript”):

game:GetService("ReplicatedStorage").tablePlrs.OnServerEvent:Connect(function(player)
				table.remove(plrs, player)
			end)

thank you for reading.

You are using “player” in 2 arguments, IIRC you only need it in one

1 Like

regardless if I only need one or two it still won’t work

In my context, if there is only one player left in the game, the round ends. But currently it ignores that fact that there is only one player left and the game carries on.

First off, server scripts don’t need to be using WaitForChild.

Why do you send it over to the client, then immediately back to the server? Why not just do it all on the server, as your LivesButThisTimeItWillWok just goes right back to the server?

How is your plrs table setup. Is it like this:

plrs[game.Players.Player1.Name] = 3
local plrs = { ["Player1"] = 3 } -- the player name is the key
-- or this
plrs[game.Players.Player1] = 3
local plrs = { Player1Instance = 3 } -- the actual instance of the player

Try this table.remove(plrs, table.find(plrs,player))

1 Like

The game ends now, but the problem is that the game tells me that somehow nobody won instead of “Player1” has won the game…