Advertisement
HowToRoblox

RoleHandler

May 24th, 2021
5,423
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 1 0
  1. local roles =
  2.     {
  3.         Murderer = {1, Color3.fromRGB(221, 29, 29), script.Sword};
  4.         Sheriff = {1, Color3.fromRGB(22, 120, 240), script.Gun};
  5.         Innocent = {100, Color3.fromRGB(62, 197, 32)}
  6.     }
  7.  
  8. local rolesTable = {"Murderer", "Sheriff", "Innocent"}
  9.  
  10.  
  11. function handleGui(plr, pickedRole, weapon)
  12.    
  13.     local gui = plr.PlayerGui.PickerGui
  14.     gui.Enabled = true
  15.    
  16.     for x = 1, 10 do
  17.        
  18.         local randomRole = rolesTable[math.random(1, #rolesTable)]
  19.        
  20.         gui.Background.RoleGiven.TextColor3 = roles[randomRole][2]
  21.         gui.Background.RoleGiven.Text = randomRole
  22.        
  23.         wait(0.2)
  24.     end
  25.    
  26.     gui.Background.RoleGiven.TextColor3 = roles[pickedRole][2]
  27.     gui.Background.RoleGiven.Text = pickedRole
  28.    
  29.     if weapon then
  30.         weapon:Clone().Parent = plr.Backpack
  31.     end
  32.    
  33.     wait(2)
  34.     gui.Enabled = false
  35. end
  36.  
  37.  
  38. function checkAlive(plrRoles)
  39.    
  40.     local survivor = false
  41.     local murderer = false
  42.  
  43.     for plr, roleName in pairs(plrRoles) do
  44.  
  45.         if plr then
  46.             if roleName == "Sheriff" or roleName == "Innocent" then
  47.                
  48.                 survivor = true        
  49.  
  50.             elseif roleName == "Murderer" then
  51.                
  52.                 murderer = true
  53.             end
  54.         end
  55.     end
  56.    
  57.     return survivor, murderer
  58. end
  59.  
  60.  
  61. while true do
  62.    
  63.     while wait() do
  64.         local chars = 0
  65.         for i, plr in pairs(game.Players:GetPlayers()) do
  66.             if plr.Character then chars += 1 end
  67.         end
  68.         if chars >= 3 then break end
  69.     end
  70.    
  71.    
  72.     local plrs = game.Players:GetPlayers()
  73.    
  74.     local plrRoles = {}
  75.    
  76.     for rolePos, roleName in pairs(rolesTable) do
  77.        
  78.         local roleInfo = roles[roleName]
  79.        
  80.         for i = 1, roleInfo[1] do
  81.            
  82.             if i <= #plrs then
  83.                
  84.                 local randomPlr = plrs[math.random(1, #plrs)]
  85.                
  86.                 if randomPlr then
  87.                    
  88.                     plrRoles[randomPlr] = roleName
  89.                    
  90.                     table.remove(plrs, table.find(plrs, randomPlr))
  91.                    
  92.                    
  93.                     local char = randomPlr.Character
  94.                     local hum = char:WaitForChild("Humanoid")
  95.                    
  96.                     hum.Died:Connect(function()
  97.                        
  98.                         plrRoles[randomPlr] = nil
  99.                     end)
  100.                    
  101.                    
  102.                     coroutine.resume(coroutine.create(function()
  103.                        
  104.                         handleGui(randomPlr, roleName, roleInfo[3])
  105.                     end))
  106.                 end
  107.             end
  108.         end
  109.     end
  110.    
  111.     for i = 1, 180 do
  112.        
  113.         local survivor, murderer = checkAlive(plrRoles)
  114.        
  115.         if survivor and not murderer or murderer and not survivor or not murderer and not survivor then
  116.             break
  117.         end
  118.        
  119.         wait(1)
  120.     end
  121.    
  122.     local survivor, murderer = checkAlive(plrRoles)
  123.    
  124.    
  125.     if survivor then   
  126.         print("Innocents win!")
  127.            
  128.     elseif murderer then
  129.         print("Murderer wins!")
  130.        
  131.     else
  132.         print("Draw!")
  133.     end
  134.    
  135.    
  136.     for i, plr in pairs(game.Players:GetPlayers()) do
  137.         plr.Backpack:ClearAllChildren()
  138.        
  139.         if plr.Character then
  140.            
  141.             for i, d in pairs(plr.Character:GetDescendants()) do
  142.                 if d:IsA("Tool") then d:Destroy() end
  143.             end
  144.         end
  145.     end
  146.    
  147.     wait(5)
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement