Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- 1v1 System made by: Legosweat (bo#0912)
- --]]
- local winstore = game:GetService("DataStoreService"):GetOrderedDataStore("Wins")
- local coinstore = game:GetService("DataStoreService"):GetOrderedDataStore("Coins")
- local Pad1 = script.Parent:WaitForChild("pad1")
- local Pad2 = script.Parent:WaitForChild("pad2")
- local MatchPad1 = script.Parent:WaitForChild("matchpad1")
- local MatchPad2 = script.Parent:WaitForChild("matchpad2")
- local AfterMatchPad = script.Parent:WaitForChild("aftermatchtp")
- local Board = script.Parent:WaitForChild("board")
- local Main_Frame = Board:WaitForChild("SurfaceGui"):WaitForChild("Frame")
- local TimerFrame = Main_Frame:WaitForChild("timer")
- local Board_Timer = TimerFrame:WaitForChild("timer")
- local Board_TimerLabel = TimerFrame:WaitForChild("timerlabel")
- local vs_Frame = Main_Frame:WaitForChild("vs")
- local Board_Player1 = vs_Frame:WaitForChild("player1")
- local Board_Player2 = vs_Frame:WaitForChild("player2")
- local Folder = game.Lighting:WaitForChild("Extras")
- local Settings = require(Folder:WaitForChild("SettingsScript"))
- local Endeded = Folder:WaitForChild("Endeded")
- --local DataManager = require(Folder:WaitForChild("ModuleScript"))-- DataManager:ChangeStat(player, 'Coins', CoinsForWin)
- local ClientUpdate = Folder:WaitForChild("UpdateClient")
- local Player1
- local Player2
- local Started = false
- local function AddCoins(player, add)
- local current = coinstore:GetAsync(player.UserId)
- ClientUpdate:FireClient(player, "Coins", current+add)
- coinstore:IncrementAsync(player.UserId, add)
- end
- local function AddWins(player, add)
- local current = winstore:GetAsync(player.UserId)
- ClientUpdate:FireClient(player, "Wins", current+add)
- winstore:IncrementAsync(player.UserId, add)
- end
- local function removewep(ppl)
- local Wep = ppl.Backpack:FindFirstChild(Settings.ItemName)
- local EqWep = ppl.Character:FindFirstChild(Settings.ItemName)
- if Wep then
- Wep:Remove()
- elseif EqWep then
- EqWep:Remove()
- end
- end
- local function winnerg(ppl)
- ppl.Character:MoveTo(AfterMatchPad.Position)
- Board_TimerLabel.Text = ppl.Name .. " won the match!"
- AddCoins(ppl, Settings.CoinsForWin)
- AddWins(ppl, 1)
- if ppl.Character.Humanoid.Health < 100 then
- ppl.Character.Humanoid.Health = 100
- end
- if not Settings.GiveSword then
- Settings.GiveToolsBack(ppl)
- else
- removewep(ppl)
- end
- end
- game.Players.PlayerAdded:connect(function(player)
- local coinget = coinstore:GetAsync(player.UserId)
- local winget = winstore:GetAsync(player.UserId)
- if not coinget or not winget then
- coinstore:SetAsync(player.UserId, 0)
- winstore:SetAsync(player.UserId, 0)
- elseif coinget and winget then
- ClientUpdate:FireClient(player, "Coins", coinget)
- ClientUpdate:FireClient(player, "Wins", winget)
- end
- end)
- -- Start loop
- -- Starting connections
- spawn(function() -- loop to start game in another thread =)
- while wait() do
- spawn(function()
- --Pad2
- local lmao = Pad2.Touched:connect(function() end)
- while (not Started) do
- wait(.1)
- local Touching = Pad2:GetTouchingParts()
- local Player = nil
- local StillOn = false
- for i,v in pairs (Touching) do
- if v.Parent:FindFirstChild("Humanoid") then
- if v.Parent == Player2 then
- StillOn = true
- end
- end
- end
- if not StillOn then
- Player2 = nil
- Board_Player2.Text = "p2"
- for i,v in pairs (Touching) do
- if v.Parent:FindFirstChild("Humanoid") then
- if Settings.HasToolsAllowed(game.Players:GetPlayerFromCharacter(v.Parent)) then
- Player = v.Parent
- end
- end
- end
- end
- if Player then
- Player2 = Player
- Board_Player2.Text = Player.Name
- end
- end
- lmao:Disconnect()
- end)
- spawn(function()
- --Pad1
- local lmao = Pad1.Touched:connect(function() end)
- while (not Started) do
- wait(.1)
- local Touching = Pad1:GetTouchingParts()
- local Player = nil
- local StillOn = false
- for i,v in pairs (Touching) do
- if v.Parent:FindFirstChild("Humanoid") then
- if v.Parent == Player1 then
- StillOn = true
- end
- end
- end
- if not StillOn then
- Player1 = nil
- Board_Player1.Text = "p1"
- for i,v in pairs (Touching) do
- if v.Parent:FindFirstChild("Humanoid") then
- if Settings.HasToolsAllowed(game.Players:GetPlayerFromCharacter(v.Parent)) then
- Player = v.Parent
- end
- end
- end
- end
- if Player then
- Player1 = Player
- Board_Player1.Text = Player.Name
- end
- end
- lmao:Disconnect()
- end)
- -----------------------------------------------------
- -- Reset data ---------------------------------------
- Board_TimerLabel.Text = "Waiting for opponents"
- Board_Timer.Text = "00:00"
- if not Player1 then
- Board_Player1.Text = "p1"
- end
- if not Player2 then
- Board_Player2.Text = "p2"
- end
- Endeded.Value = false
- -----------------------------------------------------
- -- Make loop to trigger game start ------------------
- repeat -- lag conductor ... rip
- wait(.1)
- until Player1 and Player2
- -----------------------------------------------------
- -- The game timer -----------------------------------
- Board_TimerLabel.Text = "Starting count down"
- for i=Settings.RoundWaitTime,1,-1 do --Start Count Down
- if not Player1 or not Player2 then
- break
- end
- if i > 10 then
- Board_Timer.Text = "00:"..i
- elseif i < 10 then
- Board_Timer.Text = "00:0"..i
- end
- wait(1)
- end
- Board_Timer.Text = "00:00"
- Started = true
- if Player1 and Player2 then
- local player1char
- local player2char
- local Player1 = game.Players:GetPlayerFromCharacter(Player1)
- local Player1Death = Player1.Character.Humanoid.Died:connect(function()
- player1char = Player1.CharacterAdded:connect(function(char)
- Player1 = nil
- Endeded.Value = true
- wait(.1)
- char:MoveTo(AfterMatchPad.Position)
- end)
- end)
- local Player2 = game.Players:GetPlayerFromCharacter(Player2)
- local Player2Death = Player2.Character.Humanoid.Died:connect(function()
- player2char = Player2.CharacterAdded:connect(function(char)
- Player2 = nil
- Endeded.Value = true
- wait(.1)
- char:MoveTo(AfterMatchPad.Position)
- end)
- end)
- Board_TimerLabel.Text = "Match in progress"
- Player1.Character:MoveTo(MatchPad1.Position)
- Player2.Character:MoveTo(MatchPad2.Position)
- if Settings.GiveSword then
- local give1 = Settings.Item:Clone()
- local give2 = Settings.Item:Clone()
- give1.Parent = Player1.Backpack
- give2.Parent = Player2.Backpack
- else
- Settings.TakeTools(Player1)
- Settings.TakeTools(Player2)
- end
- local eek = Endeded.Changed:connect(function(val)
- if val then
- if Player1 and not Player2 or not Player1 and Player2 then -- Winner variable didnt work
- if Player1 then
- winnerg(Player1)
- Player1 = nil
- elseif Player2 then
- winnerg(Player2)
- Player2 = nil
- end
- elseif not Player1 and not Player2 then
- Board_TimerLabel.Text = "Tie- No one won the match! 1"
- else
- Board_TimerLabel.Text = "Tie- Ran out of time!"
- if Player1 then
- Player1.Character:MoveTo(AfterMatchPad.Position)
- removewep(Player1)
- Player1 = nil
- end
- if Player2 then
- Player2.Character:MoveTo(AfterMatchPad.Position)
- removewep(Player2)
- Player2 = nil
- end
- end
- end
- end)
- for i=Settings.RoundTime,1,-1 do --Start Count Down
- if not Player1 or not Player2 then
- break
- end
- if i > 10 then
- Board_Timer.Text = "00:"..i
- elseif i < 10 then
- Board_Timer.Text = "00:0"..i
- end
- if i<=1 then
- Endeded.Value = true
- end
- wait(1)
- end
- Board_Timer.Text = "00:00"
- wait(5)
- repeat
- Player1 = nil
- Player2 = nil
- wait(.1)
- until not Player1 and not Player2
- -- disconnect for less lag?
- eek:Disconnect()
- Player1Death:Disconnect()
- Player2Death:Disconnect()
- player1char:Disconnect()
- player2char:Disconnect()
- end
- Started = false
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement