Advertisement
HowToRoblox

VotekickHandler

Jul 7th, 2020
3,464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. local votekickCmd = "!votekick"
  2.  
  3. local cooldown = 60
  4. local plrsOnCooldown = {}
  5.  
  6. local timeForVote = 10
  7.  
  8. local isVotingForKick = false
  9. local plrsVoted = {}
  10.  
  11. local votesForKick = 0
  12.  
  13. local systemMsgRE = game.ReplicatedStorage:WaitForChild("CreateSystemMessage")
  14.  
  15.  
  16. game.Players.PlayerAdded:Connect(function(plr)
  17.    
  18.     plr.Chatted:Connect(function(msg)
  19.        
  20.         if string.sub(msg, 1, string.len(votekickCmd)) == votekickCmd and not isVotingForKick then
  21.            
  22.             local plrVoted = game.Players:FindFirstChild(string.sub(msg, string.len(votekickCmd) + 2))
  23.            
  24.             if plrVoted and not plrsOnCooldown[plr] then
  25.                
  26.                 plrsOnCooldown[plr] = true
  27.                
  28.                 isVotingForKick = true
  29.                 votesForKick = 0
  30.                
  31.                 systemMsgRE:FireAllClients("[VOTEKICK] Type 'yes' to vote for " .. plrVoted.Name .. " to be kicked. Type 'no' to ignore the vote.")
  32.                
  33.                 wait(timeForVote)
  34.                
  35.                 isVotingForKick = false
  36.                
  37.                 if votesForKick >= math.ceil(#game.Players:GetPlayers()/2) then plrVoted:Kick("You have been votekicked") end
  38.                
  39.                 wait(cooldown - timeForVote)
  40.                 plrsOnCooldown[plr] = nil
  41.             end
  42.            
  43.         elseif isVotingForKick then
  44.            
  45.             if msg == "yes" then
  46.                
  47.                 if plrsVoted[plr] ~= "yes" then
  48.                    
  49.                     votesForKick = votesForKick + 1
  50.                 end
  51.                 plrsVoted[plr] = "yes"
  52.                
  53.             elseif msg == "no" then
  54.                
  55.                 if plrsVoted[plr] == "yes" then
  56.                    
  57.                     votesForKick = votesForKick - 1
  58.                 end
  59.                 plrsVoted[plr] = "no"
  60.             end    
  61.         end
  62.     end)
  63. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement