So basically I am trying to set up do a matchmaking that will give each players a target. So basically they hunt each others.
So far I have come up with this:
local players = {}
local alive = {}
local dead = {}
--------------------------
game.Players.PlayerAdded:connect(function(player)
table.insert(players, player.Name)
end)
game.Players.PlayerRemoving:connect(function(player)
for i=1, #players do
if players[i] == player.Name then
table.remove(players, i)
end
end
end)
function assign()
local taken = {} -- numbers taken so far
for i=1, #players do
local designation = {}
local target = math.random(1, game.Players.Numplayers)
local take = false
for i,v in pairs(taken) do -- check if number is taken
if v == target then
take = true
end
end
if take == false then -- number ain't taken so player is added to list
designation.Name = players[i]
designation.Target = target
table.insert(alive, designation)
else
-- meh
end
end
end
I am unsure how to make the computer give a new number to a player if the old one is taken. And it needs to be able to give number 0 if the number of players is impair (So 1 person has no target at first). Any ideas?

1 comment
The post isn't even related to data saving/loading