Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED] Getting an error with table.remove saying "attempt to index number with remove"?

Hello, Scripters, I'm currently making a teleport system to teleport players to an arena but I'm having an issue with table.remove. I'm using table.remove to a spawn pad that has been already used but I get an error saying attempt to index number with 'remove'. If you can help me, I will very much appreciate it. Thanks! :)

Here is the block of code!

local function SwordFight()
	local CurrentPlayersInRound = Players:GetChildren()
	local SpawnPadsFolder = arenaArea:WaitForChild("Teleports")
	local SpawnPadsTable = SpawnPadsFolder:GetChildren()
	
	for table, player in pairs(CurrentPlayersInRound) do
		local RandomSpawnPad = math.random(1,#SpawnPadsTable)
		local SpawnPad = SpawnPadsTable[RandomSpawnPad]
		
		local SpawnPadPosition = SpawnPad.Position
		local char = player.Character
		local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
		
		HumanoidRootPart.Position = SpawnPadPosition
		table.remove(SpawnPadsTable, RandomSpawnPad)
	end
end

2 comments

0

why not just do SpawnPadsTable[RandomSpawnPad]:Destroy()

0

you need to index the number of the object's ocation in the table

1 answer

Sorry for wasting some of your time, I had put a space between the comma and the index in the table I wanted to remove

This discussion is preserved as it was. New answers, comments, and votes are closed.