Advertisement
Guest User

Untitled

a guest
May 26th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.11 KB | None | 0 0
  1. --[[
  2. 1v1 System made by: Legosweat (bo#0912)
  3. --]]
  4. local winstore = game:GetService("DataStoreService"):GetOrderedDataStore("Wins")
  5. local coinstore = game:GetService("DataStoreService"):GetOrderedDataStore("Coins")
  6.  
  7. local Pad1 = script.Parent:WaitForChild("pad1")
  8. local Pad2 = script.Parent:WaitForChild("pad2")
  9. local MatchPad1 = script.Parent:WaitForChild("matchpad1")
  10. local MatchPad2 = script.Parent:WaitForChild("matchpad2")
  11. local AfterMatchPad = script.Parent:WaitForChild("aftermatchtp")
  12. local Board = script.Parent:WaitForChild("board")
  13.     local Main_Frame = Board:WaitForChild("SurfaceGui"):WaitForChild("Frame")
  14.     local TimerFrame = Main_Frame:WaitForChild("timer")
  15.         local Board_Timer = TimerFrame:WaitForChild("timer")
  16.         local Board_TimerLabel = TimerFrame:WaitForChild("timerlabel")
  17.     local vs_Frame = Main_Frame:WaitForChild("vs")
  18.         local Board_Player1 = vs_Frame:WaitForChild("player1")
  19.         local Board_Player2 = vs_Frame:WaitForChild("player2")
  20. local Folder = game.Lighting:WaitForChild("Extras")
  21.     local Settings = require(Folder:WaitForChild("SettingsScript"))
  22.     local Endeded = Folder:WaitForChild("Endeded")
  23.     --local DataManager = require(Folder:WaitForChild("ModuleScript"))-- DataManager:ChangeStat(player, 'Coins', CoinsForWin)
  24.     local ClientUpdate = Folder:WaitForChild("UpdateClient")
  25.    
  26. local Player1
  27. local Player2
  28. local Started = false
  29.  
  30. local function AddCoins(player, add)
  31.     local current = coinstore:GetAsync(player.UserId)
  32.     ClientUpdate:FireClient(player, "Coins", current+add)
  33.     coinstore:IncrementAsync(player.UserId, add)
  34. end
  35.  
  36. local function AddWins(player, add)
  37.     local current = winstore:GetAsync(player.UserId)
  38.     ClientUpdate:FireClient(player, "Wins", current+add)
  39.     winstore:IncrementAsync(player.UserId, add)
  40. end
  41.  
  42. local function removewep(ppl)
  43.     local Wep = ppl.Backpack:FindFirstChild(Settings.ItemName)
  44.     local EqWep = ppl.Character:FindFirstChild(Settings.ItemName)
  45.     if Wep then
  46.         Wep:Remove()
  47.     elseif EqWep then
  48.         EqWep:Remove()
  49.     end
  50. end
  51.  
  52. local function winnerg(ppl)
  53.     ppl.Character:MoveTo(AfterMatchPad.Position)
  54.     Board_TimerLabel.Text = ppl.Name .. " won the match!"
  55.     AddCoins(ppl, Settings.CoinsForWin)
  56.     AddWins(ppl, 1)
  57.     if ppl.Character.Humanoid.Health < 100 then
  58.         ppl.Character.Humanoid.Health = 100
  59.     end
  60.     if not Settings.GiveSword then
  61.         Settings.GiveToolsBack(ppl)
  62.     else
  63.         removewep(ppl)
  64.     end
  65. end
  66.  
  67. game.Players.PlayerAdded:connect(function(player)
  68.     local coinget = coinstore:GetAsync(player.UserId)
  69.     local winget = winstore:GetAsync(player.UserId)
  70.     if not coinget or not winget then
  71.         coinstore:SetAsync(player.UserId, 0)
  72.         winstore:SetAsync(player.UserId, 0)
  73.     elseif coinget and winget then
  74.         ClientUpdate:FireClient(player, "Coins", coinget)
  75.         ClientUpdate:FireClient(player, "Wins", winget)
  76.     end
  77. end)
  78.  
  79. -- Start loop
  80. -- Starting connections
  81.  
  82. spawn(function() -- loop to start game in another thread =)
  83.     while wait() do
  84.         spawn(function()
  85.             --Pad2
  86.             local lmao = Pad2.Touched:connect(function() end)
  87.             while (not Started) do
  88.                 wait(.1)
  89.                 local Touching = Pad2:GetTouchingParts()
  90.                 local Player = nil
  91.                 local StillOn = false
  92.                
  93.                 for i,v in pairs (Touching) do
  94.                     if v.Parent:FindFirstChild("Humanoid") then
  95.                         if v.Parent == Player2 then
  96.                             StillOn = true
  97.                         end
  98.                     end
  99.                 end
  100.                 if not StillOn then
  101.                     Player2 = nil
  102.                     Board_Player2.Text = "p2"
  103.                     for i,v in pairs (Touching) do
  104.                         if v.Parent:FindFirstChild("Humanoid") then
  105.                             if Settings.HasToolsAllowed(game.Players:GetPlayerFromCharacter(v.Parent)) then
  106.                                 Player = v.Parent
  107.                             end
  108.                         end
  109.                     end
  110.                 end
  111.                 if Player then
  112.                     Player2 = Player
  113.                     Board_Player2.Text = Player.Name
  114.                 end
  115.             end
  116.             lmao:Disconnect()
  117.         end)
  118.         spawn(function()
  119.             --Pad1
  120.             local lmao = Pad1.Touched:connect(function() end)
  121.             while (not Started) do
  122.                 wait(.1)
  123.                 local Touching = Pad1:GetTouchingParts()
  124.                 local Player = nil
  125.                 local StillOn = false
  126.                 for i,v in pairs (Touching) do
  127.                     if v.Parent:FindFirstChild("Humanoid") then
  128.                         if v.Parent == Player1 then
  129.                             StillOn = true
  130.                         end
  131.                     end
  132.                 end
  133.                 if not StillOn then
  134.                     Player1 = nil
  135.                     Board_Player1.Text = "p1"
  136.                     for i,v in pairs (Touching) do
  137.                         if v.Parent:FindFirstChild("Humanoid") then
  138.                             if Settings.HasToolsAllowed(game.Players:GetPlayerFromCharacter(v.Parent)) then
  139.                                 Player = v.Parent
  140.                             end
  141.                         end
  142.                     end
  143.                 end
  144.                 if Player then
  145.                     Player1 = Player
  146.                     Board_Player1.Text = Player.Name
  147.                 end
  148.             end
  149.             lmao:Disconnect()
  150.         end)
  151.         -----------------------------------------------------
  152.         -- Reset data ---------------------------------------
  153.         Board_TimerLabel.Text = "Waiting for opponents"
  154.         Board_Timer.Text = "00:00"
  155.         if not Player1 then
  156.             Board_Player1.Text = "p1"
  157.         end
  158.         if not Player2 then
  159.             Board_Player2.Text = "p2"
  160.         end
  161.         Endeded.Value = false
  162.        
  163.         -----------------------------------------------------
  164.         -- Make loop to trigger game start ------------------
  165.         repeat -- lag conductor ... rip
  166.             wait(.1)
  167.         until Player1 and Player2
  168.        
  169.         -----------------------------------------------------
  170.         -- The game timer -----------------------------------
  171.         Board_TimerLabel.Text = "Starting count down"
  172.         for i=Settings.RoundWaitTime,1,-1 do    --Start Count Down
  173.             if not Player1 or not Player2 then
  174.                 break
  175.             end
  176.             if i > 10 then
  177.                 Board_Timer.Text = "00:"..i
  178.             elseif i < 10 then
  179.                 Board_Timer.Text = "00:0"..i
  180.             end
  181.             wait(1)
  182.         end
  183.         Board_Timer.Text = "00:00"
  184.        
  185.         Started = true
  186.         if Player1 and Player2 then
  187.             local player1char
  188.             local player2char
  189.            
  190.             local Player1 = game.Players:GetPlayerFromCharacter(Player1)
  191.             local Player1Death = Player1.Character.Humanoid.Died:connect(function()
  192.                 player1char = Player1.CharacterAdded:connect(function(char)
  193.                     Player1 = nil
  194.                     Endeded.Value = true
  195.                     wait(.1)
  196.                     char:MoveTo(AfterMatchPad.Position)
  197.                 end)
  198.             end)
  199.            
  200.             local Player2 = game.Players:GetPlayerFromCharacter(Player2)
  201.             local Player2Death = Player2.Character.Humanoid.Died:connect(function()
  202.                 player2char = Player2.CharacterAdded:connect(function(char)
  203.                     Player2 = nil
  204.                     Endeded.Value = true
  205.                     wait(.1)
  206.                     char:MoveTo(AfterMatchPad.Position)
  207.                 end)
  208.             end)
  209.            
  210.             Board_TimerLabel.Text = "Match in progress"
  211.             Player1.Character:MoveTo(MatchPad1.Position)
  212.             Player2.Character:MoveTo(MatchPad2.Position)
  213.             if Settings.GiveSword then
  214.                 local give1 = Settings.Item:Clone()
  215.                 local give2 = Settings.Item:Clone()
  216.                 give1.Parent = Player1.Backpack
  217.                 give2.Parent = Player2.Backpack
  218.             else
  219.                 Settings.TakeTools(Player1)
  220.                 Settings.TakeTools(Player2)
  221.             end
  222.            
  223.             local eek = Endeded.Changed:connect(function(val)
  224.                 if val then
  225.                     if Player1 and not Player2 or not Player1 and Player2 then -- Winner variable didnt work
  226.                         if Player1 then
  227.                             winnerg(Player1)
  228.                             Player1 = nil
  229.                         elseif Player2 then
  230.                             winnerg(Player2)
  231.                             Player2 = nil
  232.                         end
  233.                     elseif not Player1 and not Player2 then
  234.                         Board_TimerLabel.Text = "Tie- No one won the match! 1"
  235.                     else
  236.                         Board_TimerLabel.Text = "Tie- Ran out of time!"
  237.                         if Player1 then
  238.                             Player1.Character:MoveTo(AfterMatchPad.Position)
  239.                             removewep(Player1)
  240.                             Player1 = nil
  241.                         end
  242.                         if Player2 then
  243.                             Player2.Character:MoveTo(AfterMatchPad.Position)
  244.                             removewep(Player2)
  245.                             Player2 = nil
  246.                         end
  247.                     end
  248.                 end
  249.             end)
  250.            
  251.             for i=Settings.RoundTime,1,-1 do    --Start Count Down
  252.                 if not Player1 or not Player2 then
  253.                     break
  254.                 end
  255.                 if i > 10 then
  256.                     Board_Timer.Text = "00:"..i
  257.                 elseif i < 10 then
  258.                     Board_Timer.Text = "00:0"..i
  259.                 end
  260.                 if i<=1 then
  261.                     Endeded.Value = true
  262.                 end
  263.                 wait(1)
  264.             end
  265.             Board_Timer.Text = "00:00"
  266.            
  267.             wait(5)
  268.            
  269.             repeat
  270.                 Player1 = nil
  271.                 Player2 = nil
  272.                 wait(.1)
  273.             until not Player1 and not Player2
  274.             -- disconnect for less lag?
  275.             eek:Disconnect()
  276.             Player1Death:Disconnect()
  277.             Player2Death:Disconnect()
  278.             player1char:Disconnect()
  279.             player2char:Disconnect()
  280.         end
  281.         Started = false
  282.     end
  283. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement