Taking a random number from a pool

i am trying to give all the players a “character” from a pool
(sorta like the game werewolves)

i have a script that sends a remote event to all clients and i want to give each clients a different number from a pool (i can then link each number to a character)

(i have no script because nothing i have tried so far has worked)

would i need to use a module script? or something with math.random?

2 Likes

Can you give me some more details? like the numbers, and amount of players?
and is it a script or a local script + where to put?

  • the numbers would be numbers from 1-15 (most of the time not all numbers would be given out)

  • the ammount of players would be between 3-15 (i’m using a table with all the players in it)

  • the script that sends the remote event is a normal script, it is sending it to a local scripts from the players which would make a little animation to show what character they are. what i’m planning is to have either the local script or the script select a random number that hasn’t been chosen yet.
    then in the local script i would pair each number with a character example:

if number == 1 then

     (insert little animation for character A)

elseif number == 2 then

     (insert little animation for character B)

end

You can do this to assign a random number to each player by using tables

local playerAmount = #plrtable -- table with players in it
local numberTable = {}
for i = 1, playerAmount do
table.insert(numberTable, i)
end

for i,v in pairs(plrtable) do
local randomNumber = math.random(1,#numberTable)
local chosenNumber = numberTable[randomNumber] -- get number here
game.ReplicatedStorage.RemoteEvent:FireClient(v, chosenNumber)
table.remove(numberTable, randomNumber)
end