deve690

Untitled

Jul 4th, 2024 (edited)
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.62 KB | Source Code | 0 0
  1. local ServerScriptService = game:GetService("ServerScriptService")
  2. local MarketplaceService = game:GetService("MarketplaceService")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4.  
  5. local EndMatch = game.ServerScriptService.Network.EndMatch
  6.  
  7. local LocalNetwork = ReplicatedStorage.LocalNetwork
  8. local P2N = LocalNetwork.P2N
  9. local SpawnEvent = LocalNetwork.Spawn
  10. local HealthChange = LocalNetwork.HealthChange
  11.  
  12. local Chars = ReplicatedStorage.Chars:GetChildren()
  13. local Charss = game.ReplicatedStorage:WaitForChild("Chars")
  14.  
  15. local CharSelectorUI = game.StarterGui.CharSelector
  16. local CharSelectorMain = game.StarterGui.CharSelector.Main
  17. local Sample = CharSelectorMain.CharSelect.List.Store.Sample
  18.  
  19. local PGS = {
  20.  
  21.     PG1 = 806554024,
  22.     PG2 = 807124029,
  23.     PG3 = 806655018,
  24.     SPG = 806916035,
  25.  
  26. }
  27.  
  28. game.Players.PlayerAdded:Connect(function(Player)
  29.     local CharName = Instance.new("StringValue")
  30.     CharName.Name = "CName"
  31.     CharName.Parent = Player
  32.     --local CharPos = Instance.new("BoolValue")
  33.     --CharPos.Name = "OnLeft"
  34.     --CharPos.Parent = Player
  35.     local SpValue = Instance.new("BoolValue")
  36.     SpValue.Name = "Spawn"
  37.     SpValue.Parent = Player
  38.     local SP1Value = Instance.new("BoolValue")
  39.     SP1Value.Name = "Spawn1"
  40.     SP1Value.Parent = Player
  41.     local SP2Value = Instance.new("BoolValue")
  42.     SP2Value.Name = "Hit"
  43.     SP2Value.Parent = Player
  44.    
  45.     game.Players:GetPlayers()[1].Character.PrimaryPart.CFrame = workspace.Model.Spawn1.CFrame + Vector3.new(0, 4, 0)
  46.     game.Players:GetPlayers()[2].Character.PrimaryPart.CFrame = workspace.Model.Spawn2.CFrame + Vector3.new(0, 4, 0)
  47.    
  48. end)
  49.  
  50. for I, V in ipairs(Chars) do
  51.     local VPF = Instance.new("ViewportFrame")
  52.     VPF.Parent = CharSelectorMain.CharSelect.List
  53.     VPF.Name = V.Name
  54.     VPF.BackgroundTransparency = 1
  55.     VPF.AnchorPoint = Vector2.new(0.5,0.5)
  56.     VPF.Position = UDim2.new(0.5, 0, 0.5, 0)
  57.     VPF.Size = UDim2.new(1,0,1,0)
  58.  
  59.     local CChar = V.StarterCharacter:Clone()
  60.     CChar.Parent = VPF
  61.  
  62.     local BTN = Sample:Clone()
  63.     BTN.Visible = true
  64.     BTN.Parent = VPF
  65.     BTN.Name = V.Name
  66.     BTN.Size = UDim2.new(1,0,1,0)
  67.     BTN.Position = UDim2.new(0.5, 0, 0.5, 0)
  68.     BTN.ImageColor3 = V:GetAttribute("Color")
  69.     BTN.AnchorPoint = Vector2.new(0.5,0.5)
  70.     BTN.Text.Text = V.StarterCharacter:GetAttribute("CHAR")
  71.     BTN:AddTag("CharButton")
  72.     BTN:AddTag("Button")
  73.  
  74.     if I < 5 then
  75.         BTN:SetAttribute("Own", true)
  76.     end
  77.  
  78.     if I > 4 then
  79.  
  80.         local h,s,v = BTN.ImageColor3:ToHSV()
  81.         v = 0.43137258291244507
  82.         local newcolor = Color3.fromHSV(h,s,v)
  83.  
  84.         BTN.ImageColor3 = newcolor
  85.         BTN.Interactable = true
  86.     end
  87. end
  88.  
  89. local function CheckPas(Player)
  90.  
  91.     for I, V in pairs(PGS) do
  92.  
  93.         local HasPG = false
  94.  
  95.         local success, message = pcall(function()
  96.  
  97.             HasPG = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, V)
  98.  
  99.         end)
  100.        
  101.         if not success then
  102.  
  103.             warn("Error while checking if player has pass: " .. tostring(message))
  104.  
  105.             return
  106.  
  107.         end
  108.        
  109.         task.delay(2, function()
  110.            
  111.             if HasPG then
  112.  
  113.                 local List = Player.PlayerGui:WaitForChild("CharSelector").Main.CharSelect.List
  114.  
  115.                 if I == "PG1" then
  116.  
  117.                     List["FairyMan"]["FairyMan"].ImageColor3 = Charss["FairyMan"]:GetAttribute("Color")
  118.                     List["FairyWoman"]["FairyWoman"].ImageColor3 = Charss["FairyWoman"]:GetAttribute("Color")
  119.  
  120.                     List["FairyWoman"]["FairyWoman"]:SetAttribute("Own", true)
  121.                     List["FairyMan"]["FairyMan"]:SetAttribute("Own", true)
  122.  
  123.                 end
  124.  
  125.                 if I == "PG2" then
  126.  
  127.                     List["Ninja"]["Ninja"].ImageColor3 = Charss["Ninja"]:GetAttribute("Color")
  128.                     List["Samurai"]["Samurai"].ImageColor3 = Charss["Samurai"]:GetAttribute("Color")
  129.  
  130.                     List["Ninja"]["Ninja"]:SetAttribute("Own", true)
  131.                     List["Samurai"]["Samurai"]:SetAttribute("Own", true)
  132.  
  133.                 end
  134.  
  135.                 if I == "PG3" then
  136.  
  137.                     List["SPMan"]["SPMan"].ImageColor3 = Charss["SPMan"]:GetAttribute("Color")
  138.                     List["SPWoman"]["SPWoman"].ImageColor3 = Charss["SPWoman"]:GetAttribute("Color")
  139.  
  140.                     List["SPMan"]["SPMan"]:SetAttribute("Own", true)
  141.                     List["SPWoman"]["SPWoman"]:SetAttribute("Own", true)
  142.  
  143.                 end
  144.  
  145.                 if I == "SPG" then
  146.  
  147.                     List["Vampire"]["Vampire"].ImageColor3 = Charss["Vampire"]:GetAttribute("Color")
  148.                     List["WizWoman"]["WizWoman"].ImageColor3 = Charss["WizWoman"]:GetAttribute("Color")
  149.                     List["WizardMan"]["WizardMan"].ImageColor3 = Charss["WizardMan"]:GetAttribute("Color")
  150.  
  151.                     List["Vampire"]["Vampire"]:SetAttribute("Own", true)
  152.                     List["WizWoman"]["WizWoman"]:SetAttribute("Own", true)
  153.                     List["WizardMan"]["WizardMan"]:SetAttribute("Own", true)
  154.  
  155.                 end
  156.  
  157.             end
  158.            
  159.         end)
  160.        
  161.         local Pass = Player:WaitForChild("Inv").Pass.Value
  162.        
  163.         print(Pass, "THE PASS VALUE")
  164.        
  165.         task.delay(4, function()
  166.             print(Pass, "THE PASS VALUE after the delay")
  167.             if Pass == 1 then
  168.                 local List = Player.PlayerGui:WaitForChild("CharSelector").Main.CharSelect.List
  169.  
  170.                 for _, V in ipairs(List:GetDescendants()) do
  171.                    
  172.                     if V:IsA("ImageButton") and V.Name ~= "Sample" then
  173.                         V:SetAttribute("Own", true)
  174.                         V.ImageColor3 = Charss[V.Name]:GetAttribute("Color")
  175.                     end
  176.                    
  177.                 end
  178.  
  179.             end
  180.         end)
  181.        
  182.     end
  183.  
  184. end
  185.  
  186. game.Players.PlayerAdded:Connect(function(Player)
  187.  
  188.     wait()
  189.  
  190.     CheckPas(Player)
  191.  
  192. end)
  193.  
  194. MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player, purchasedPassID, purchaseSuccess)
  195.     print("PURCHASE IS CALLED")
  196.     if purchaseSuccess then
  197.         print("PURCHASE IS SUCCESS 1")
  198.         CheckPas(Player)
  199.         print("PURCHASE IS SUCCESS 2")
  200.     end
  201.  
  202. end)
  203.  
  204. P2N.OnServerEvent:Connect(function(Player, CharN)
  205.     P2N:FireAllClients(Player, CharN)
  206.  
  207.     if Player ~= game.Players:GetPlayers()[1] then
  208.         local btns = game.Players:GetPlayers()[1].PlayerGui.CharSelector.Main.CharSelect.List:GetDescendants()
  209.         for _, V in ipairs(btns) do
  210.             if V:IsA("ImageButton") then
  211.  
  212.                 if V.Name ~= CharN and V.Parent:IsA("ViewportFrame") then
  213.  
  214.                     local CC = game.ReplicatedStorage.Chars[V.Name]
  215.                     if V:GetAttribute("Own") then
  216.                         V.ImageColor3 = CC:GetAttribute("Color")
  217.                         V.Interactable = true
  218.                     else
  219.                         local C = CC:GetAttribute("Color")
  220.                         local h,s,v = C:ToHSV()
  221.                         v = 0.43137258291244507
  222.                         local newcolor = Color3.fromHSV(h,s,v)
  223.                         V.Interactable = true
  224.                         V.ImageColor3 = newcolor
  225.                     end
  226.                 elseif V.Name == CharN then
  227.                     V.Interactable = false
  228.                     V.ImageColor3 = Color3.fromRGB(120, 0, 0)
  229.                 end
  230.  
  231.             end
  232.         end
  233.     end
  234.  
  235.     if Player ~= game.Players:GetPlayers()[2] then
  236.         local btns = game.Players:GetPlayers()[2].PlayerGui.CharSelector.Main.CharSelect.List:GetDescendants()
  237.         for _, V in ipairs(btns) do
  238.             if V:IsA("ImageButton") then
  239.  
  240.                 if V.Name ~= CharN and V.Parent:IsA("ViewportFrame") then
  241.  
  242.                     local CC = game.ReplicatedStorage.Chars[V.Name]
  243.                     if V:GetAttribute("Own") then
  244.                         V.ImageColor3 = CC:GetAttribute("Color")
  245.                         V.Interactable = true
  246.                     else
  247.                         local C = CC:GetAttribute("Color")
  248.                         local h,s,v = C:ToHSV()
  249.                         v = 0.43137258291244507
  250.                         local newcolor = Color3.fromHSV(h,s,v)
  251.                         V.Interactable = true
  252.                         V.ImageColor3 = newcolor
  253.                     end
  254.                 elseif V.Name == CharN then
  255.                     V.Interactable = false
  256.                     V.ImageColor3 = Color3.fromRGB(120, 0, 0)
  257.                 end
  258.  
  259.             end
  260.         end
  261.     end
  262.  
  263. end)
  264.  
  265. local charsFolder = game.ReplicatedStorage.Chars
  266.  
  267.  
  268. local Numb = 0
  269.  
  270. local Player1IsReady = false
  271. local Player2IsReady = false
  272.  
  273. SpawnEvent.OnServerEvent:Connect(function(Player, ChosenCharacter, Action)
  274.    
  275.     Numb += 1
  276.    
  277.     local newChar
  278.    
  279.     if Player == game.Players:GetPlayers()[1] then
  280.        
  281.         newChar = charsFolder:FindFirstChild(ChosenCharacter)["StarterCharacter" .. Numb]
  282.         print("Spawning for the " .. Numb .. " Time ...")
  283.        
  284.         Player1IsReady = true
  285.         Player.RespawnLocation = workspace.Model.Spawn1
  286.         game.Players:GetPlayers()[1].Character.PrimaryPart.CFrame = workspace.Model.Spawn1.CFrame + Vector3.new(0, 4, 0)
  287.         game.Players:GetPlayers()[2].Character.PrimaryPart.CFrame = workspace.Model.Spawn2.CFrame + Vector3.new(0, 4, 0)
  288.         game.Players:GetPlayers()[1].Character.Humanoid.Health = 100
  289.         game.Players:GetPlayers()[2].Character.Humanoid.Health = 100
  290.        
  291.     end
  292.    
  293.     if Player == game.Players:GetPlayers()[2] then
  294.        
  295.         newChar = charsFolder:FindFirstChild(ChosenCharacter)["StarterCharacter" .. Numb]
  296.         print("Spawning for the " .. Numb .. " Time ...")
  297.        
  298.         Player2IsReady = true
  299.         Player.RespawnLocation = workspace.Model.Spawn2
  300.         game.Players:GetPlayers()[2].Character.PrimaryPart.CFrame = workspace.Model.Spawn2.CFrame + Vector3.new(0, 4, 0)
  301.         game.Players:GetPlayers()[1].Character.PrimaryPart.CFrame = workspace.Model.Spawn1.CFrame + Vector3.new(0, 4, 0)
  302.         game.Players:GetPlayers()[2].Character.Humanoid.Health = 100
  303.         game.Players:GetPlayers()[1].Character.Humanoid.Health = 100
  304.        
  305.     end
  306.    
  307.     local Character = Player.Character
  308.    
  309.     if newChar:FindFirstChild("HumanoidRootPart") then
  310.        
  311.         newChar.PrimaryPart = newChar.HumanoidRootPart
  312.         newChar:SetPrimaryPartCFrame(Character.HumanoidRootPart.CFrame)
  313.        
  314.     elseif newChar:FindFirstChild("Torso") and not newChar:FindFirstChild("HumanoidRootPart") then
  315.        
  316.         newChar.PrimaryPart = newChar.Torso
  317.         newChar:SetPrimaryPartCFrame(Character.Torso.CFrame)
  318.        
  319.     end
  320.    
  321.     if Player.Character:FindFirstChild("Animate") then
  322.        
  323.         local anim = Player.Character:FindFirstChild("Animate"):Clone()
  324.         anim.Parent = newChar
  325.        
  326.     end
  327.    
  328.    
  329.     newChar.Name = Player.Name
  330.     Player.Character = newChar
  331.    
  332.    
  333.     local rootPart = newChar:FindFirstChild("HumanoidRootPart") or newChar:FindFirstChild("Torso")
  334.     local plrRoot = Player.Character:FindFirstChild("HumanoidRootPart") or Player.Character:FindFirstChild("Torso")
  335.    
  336.    
  337.     if rootPart and plrRoot then
  338.        
  339.         rootPart.CFrame = plrRoot.CFrame
  340.        
  341.     end
  342.    
  343.     for _, V in ipairs(Character:GetChildren()) do
  344.         if V:IsA("LocalScript") or V:IsA("Script") then
  345.             V.Parent = newChar
  346.         end
  347.     end
  348.  
  349.     newChar.Parent = workspace
  350.    
  351.     local hrp1 = game.Players:GetPlayers()[1].Character.HumanoidRootPart
  352.     local hrp2 = game.Players:GetPlayers()[2].Character.HumanoidRootPart
  353.  
  354.     game.Players:GetPlayers()[1].Character.HumanoidRootPart.CFrame = CFrame.new(hrp1.Position, hrp2.Position)
  355.     game.Players:GetPlayers()[2].Character.HumanoidRootPart.CFrame = CFrame.new(hrp2.Position, hrp1.Position)
  356.  
  357.     if Player1IsReady and Player2IsReady then
  358.  
  359.         SpawnEvent:FireAllClients()
  360.  
  361.         Player1IsReady = false
  362.         Player2IsReady = false
  363.        
  364.         print("Count Started")
  365.         EndMatch:Fire("ENDGAME")
  366.        
  367.     end
  368.    
  369.     game.Players:GetPlayers()[1].Character:WaitForChild("Torso").CollisionGroup = "Torso"
  370.     game.Players:GetPlayers()[2].Character:WaitForChild("Torso").CollisionGroup = "Torso"
  371.    
  372. end)
  373.  
  374.  
  375. HealthChange.OnServerEvent:Connect(function(Player, HPPercentage, Health)
  376.    
  377.     -- print(Player, HPPercentage, Health)
  378.     HealthChange:FireAllClients(Player.Name, HPPercentage, Health)
  379.    
  380. end)
Advertisement
Add Comment
Please, Sign In to add comment