This is not working

Hey guys. I’ve made a teleport system that should only work if the player isn’t in the listed table. However, it isn’t exactly going as planned. Any way to get this to work?

if Character and Player and not table.find(PlayersOnCooldown, Player) then
	PlayersOnCooldown[#PlayersOnCooldown + 1] = Player
	Character:PivotTo(CFrame.new(Destination.Position+Vector3.new(0, Offset, 0)))

	task.delay(1, function()
		table.remove(PlayersOnCooldown, Player)
	end)
end

This is in a .Touched event by the way.

2 Likes

table.remove takes the item’s index, not the value.

if Character and Player and not table.find(PlayersOnCooldown, Player) then
	table.insert(PlayersOnCooldown, Player)
	Character:PivotTo(CFrame.new(Destination.Position+Vector3.new(0, Offset, 0)))

	task.delay(1, function()
        -- table.find grabs the index of the provided value in the table.
        -- In this case, the value is *Player*, so it will return the index the
        -- player has in the table
		table.remove(PlayersOnCooldown, table.find(PlayersOnCooldown, Player))
	end)
end
1 Like

That worked! Thanks for your help! I can’t believe I never thought to use table.find() inside of a table.remove(). I’ll be using this a whole lot more! Thanks again! :smile:

1 Like

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