Advertisement
Remusutules

New Roles Handler Module

Nov 28th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. local RolesModule = {}
  2.  
  3. local RS = game:GetService("ReplicatedStorage")
  4. local rolesFolder = Instance.new("Folder", RS) or RS:WaitForChild("Roles")
  5. rolesFolder.Name = "Roles"
  6.  
  7. function RolesModule.AssignRoles()
  8.     local Players = game:GetService("Players")
  9.     local players = Players:GetPlayers()
  10.     local playerCount = #players
  11.  
  12.     if playerCount < 2 then
  13.         warn("Not enough players to assign both Vampire and Hunter roles.")
  14.         return
  15.     end
  16.  
  17.     local vampireIndex = math.random(1, playerCount)
  18.     local hunterIndex
  19.  
  20.     repeat
  21.         hunterIndex = math.random(1, playerCount)
  22.     until hunterIndex ~= vampireIndex
  23.  
  24.     for i, player in ipairs(players) do
  25.         local role = "Survivor"
  26.  
  27.         if i == vampireIndex then
  28.             role = "Vampire"
  29.         elseif i == hunterIndex then
  30.             role = "Hunter"
  31.         end
  32.  
  33.         local roleValue = Instance.new("StringValue")
  34.         roleValue.Name = player.Name
  35.         roleValue.Value = role
  36.         roleValue.Parent = rolesFolder--your folder
  37.     end
  38. end
  39. return RolesModule
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement