Removing A Player From A Table

Is that necessary? I’ve never used that with table inserting before (unless I wanted a specific position), it’s always automatically appended for me.

EDIT: The question isn’t sarcastic but more out of pure interest :sweat_smile:

table.insert can be used with two parameters, and it will do the same that you said.
https://gyazo.com/08e1c322613b7f8b0beac698bb22440b

Thank you, the code is working now! I’m in need of practice with tables. If you can, could you possibly link a few sources that could help?

Hmm, you’re correct, was an oversight on my part. I don’t often use table.insert but yes, it does automatically append if you don’t provide an index.

There could be a more underlying issue here. @R0BL0XIAN_D3M0 can you possibly provide the entire script?

Edit: Never mind it looks like my solution solved it.

1 Like

The entire script is around 500 lines long.

Try any snippets that involves the manipulation of those tables.

Cool !, but that is not the solution, you sure did something and did not realize that you solved the error.

Alright, thank you for the help.

Hmm, is that so?.. Thank you for the help though!

In the original post you can see @R0BL0XIAN_D3M0 index the table by number so what I provided should be the correct solution.

Other than that, we have solved his issue, if you want to continue discussion we can take it to messages. :+1:

2 Likes

Solved by, @CleverSource.

Here is the simplified version of the script that was used to solve the error.

local Players = game:GetService("Players")

local Boat1 = {}
local Boat2 = {}
local Boat3 = {}

-- Touch Event Was Here
table.insert(Boat1, #Boat1 + 1)  --Player) -- Commented The Player Bit To Prevent Error.

-- Touch Event Was Here
table.insert(Boat2, #Boat2 + 1)  --Player) -- Commented The Player Bit To Prevent Error.

-- Touch Event Was Here
table.insert(Boat3, #Boat3 + 1)  --Player) -- Commented The Player Bit To Prevent Error.

Players.PlayerRemoving:Connect(function(Player)
	for i = 1, #Boat1 do
		if Boat1[i] == Player then
			table.remove(Boat1, i)
		    warn(Player.Name..", Was Removed From Boat1 Because They've Left The Game!")
		end
	end
	for i = 1, #Boat2 do
		if Boat2[i] == Player then
			table.remove(Boat2, i)
		    warn(Player.Name..", Was Removed From Boat2 Because They've Left The Game!")
		end
	end
	for i = 1, #Boat3 do
		if Boat3[i] == Player then
			table.remove(Boat3, i)
		    warn(Player.Name..", Was Removed From Boat3 Because They've Left The Game!")
		end
	end
end)

Post From, @CleverSource :

That is a big mistake, and I will comment here so that others do not get confused.

local x = {}
table.insert(x, game.Workspace)
print(x[game.Workspace])

returns nil

local x = {}
table.insert(x, game.Workspace)
print(x[1])

returns Workspace

Why do you not just give @CleverSource’s post the solution? You don’t need to give yourself the solution and write that he gave you the solution…?

Were you mentioning me, or was it towards @Nightrains?

You, I responded to the wrong post my bad.

It’s fine. Also, I marked my code as the solution so that others with similar problems could use it as a reference for their code.

But CleverSource’s solution also provides reference to how they can solve the issue…?

Also it is against Devforum Rules to give yourself a solution that just links to the actual solution, which is what you’ve done, I am not trying to be snarky or be a “mini-mod” here but I think he deserves the solution seeing as he provided it.

3 Likes

Apologies, @CleverSource & @Maliboomer. Also, thanks for mentioning that rule.

1 Like

Would you mind pointing out which rule that is? I was trying to look through and find it, and I think I missed it.

Hey guys i have a Question, do this also works without if Boat1[i] == Player, because in my Table are just players, why should i need the If question?