How can I match up the values of one table with another

So if I have a table of players, and another tables of teleport locations and I want each player to get their own teleport locations what is the best way to do that. Like I am assigning each player their own location and nobody gets the same one everyone’s is different.

1 Like

You loop through the player table and for that index in the table assign the location at the same index in the location table to that player.
Something like:

local playerTable = game:GetService("Players"):GetPlayers() -- Or your table of players
local locationTable = {} -- Your locations

for i = 1, #playerTable do
	local player = playerTable[i]
	local location = locationTable[i]
	-- Do whatever with this location
end
2 Likes
local Game = game
local Players = Game:GetService("Players")
local Teleports = nil --Reference to an array of teleports, i.e; 'Workspace.Teleports:GetChildren()'.

for _, Player in ipairs(Players:GetPlayers()) do
	local Character = Player.Character
	if not Character then continue end
	local Teleport = table.remove(Teleports, math.random(1, #Teleports))
	Character:PivotTo(Teleport.CFrame)
end
1 Like