What I am trying to do is to make it so that there are always 3 roles that players cannot get.
These three roles will be randomized every round.
How would I come close to achieving something like this?
Here is my module script:
local CardModule = {}
CardModule.RoleLimits = {
["Werewolf"] = 2;
["Villager"] = 1;
["Hunter"] = 1;
["Tanner"] = 1;
["Seer"] = 1;
["Minion"] = 1;
["Drunk"] = 1;
["Mason"] = 2;
["Robber"] = 1;
["Troublemaker"] = 1;
["Insomniac"] = 1;
}
function shuffle(tbl)
for i = #tbl, 2, -1 do
local j = math.random(i)
tbl[i], tbl[j] = tbl[j], tbl[i]
end
return tbl
end
function CardModule.CreateRoleDeck()
local deck = {}
for role, numCopies in pairs(CardModule.RoleLimits) do
for _ = 1, numCopies do
table.insert(deck, role)
end
end
shuffle(deck)
return deck
end
function CardModule.TakeCardFromDeck(deck)
local k = #deck
local card = deck[k]
deck[k] = nil
return card
end
return CardModule
I have a script that gets the roles from the module script:
local CardModule = require(game.ReplicatedStorage.ModuleScript)
-- GameController, a server script
local roleDeck = CardModule.CreateRoleDeck()
function startGame()
local players = game.Players:GetPlayers()
assert(#players <= #roleDeck, "Not enough roles for this many players!")
for _, player in ipairs(players) do
if player:FindFirstChildWhichIsA("StringValue") then
print("wow")
else
local thing = game.Players[player.Name]
local playerRole = CardModule.TakeCardFromDeck(roleDeck)
game.ReplicatedStorage.RoleNarraration:FireClient(player, playerRole)
print(playerRole)
print(player)
local val = Instance.new("StringValue")
val.Name = playerRole
val.Parent = thing
end
end
end
The stringvalue is just so I can identify the role of a player in other scripts.