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?
Either make a datastore to store player matchmaking numbers, or just store it in a table and do random math to assign the player a number. Have an "if" check to make sure that if the random mathed number matches one already in the datastore or table, then to run the function again until their number is unique.
You can use something like math.random for this, here's an article: https://developer.roblox.com/articles/Random-Number-Generation
Here's an article on datastores for getting started if you're not familiar, in the case that you're looking to save their matchmaking number for each time they rejoin: https://developer.roblox.com/articles/Data-store