Invalid argument #2 to 'remove' (number expected, got string)

I’m trying to make a simple TP Pad system, with an indicator showing how many players are in the tp.
I keep getting line 29 errored, saying "invalid argument #2 to 'remove' (number expected, got string)

local players = game:GetService("Players")

local part = script.Parent
local val = part.amount
local amount = val.Value
local gui = part.BillboardGui.TextLabel
local plrs = part.BillboardGui.plrs
local touching = {}

part.Touched:Connect(function(hit)
	if amount < 4 then
		if players:GetPlayerFromCharacter(hit.Parent) then
			local plr = players:GetPlayerFromCharacter(hit.Parent)
			if plr and not table.find(touching,plr.Name) then
				table.insert(touching,plr.Name)
				amount = amount +1
				gui.Text = amount.."/4"
			end
		end
	end
end)

part.TouchEnded:Connect(function(hit)
	if players:GetPlayerFromCharacter(hit.Parent) then
		local plr = players:GetPlayerFromCharacter(hit.Parent)
		if plr and table.find(touching,plr.Name) then
			for i, v in ipairs(touching) do
				if v == plr.Name then
					table.remove(touching, i) --Line 29
					amount = amount -1 
					gui.Text = amount.."/4"
					return
				end
			end
		end
	end
end)

What’s wrong? What do I do?

what shows in output if you print i?

??? It started working once I did print(i)

I commited the script and published the game multiple times

i just have a way of speaking to scripts

gotta love roblox jank
–closed

I’m not really sure how to explain it, but I can provide the code for you with an explanation of the code:

Summary
part.TouchEnded:Connect(function(hit)
	if players:GetPlayerFromCharacter(hit.Parent) then
		local plr = players:GetPlayerFromCharacter(hit.Parent)
		if plr and table.find(touching,plr.Name) then
            local plrIndex = table.find(touching,plr.Name) -- finds the index of the element you want to find, in this case plr.Name
			table.remove(touching, plrIndex) -- removes said index from the table
			amount = amount -1 
			gui.Text = amount.."/4"
			return
		end
	end
end)

Note: I may have missed a few indentations, but forgive me, I am not on studio at the moment.

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