Advertisement
HowToRoblox

PartyGuiScript

Jan 1st, 2022
4,145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.06 KB | None | 0 0
  1. script.Parent.PartyGuiFrame.Visible = false
  2. script.Parent.PartyGuiFrame.PartyListFrame.Visible = true
  3. script.Parent.PartyGuiFrame.CreateFrame.PartyNameBox.Text = game.Players.LocalPlayer.Name .. "'s Party"
  4.  
  5.  
  6. script.Parent.PartyButton.MouseButton1Click:Connect(function()
  7.    
  8.     script.Parent.PartyGuiFrame.Visible = not script.Parent.PartyGuiFrame.Visible
  9. end)
  10.  
  11.  
  12. local creatingParty = false
  13. local inParty = false
  14.  
  15. script.Parent.PartyGuiFrame.CreateButton.MouseButton1Click:Connect(function()
  16.    
  17.     if inParty then return end
  18.    
  19.     creatingParty = not creatingParty
  20.    
  21.     if creatingParty then
  22.        
  23.         script.Parent.PartyGuiFrame.CreateButton.Text = "RETURN"
  24.        
  25.         script.Parent.PartyGuiFrame.CreateFrame.Visible = true
  26.         script.Parent.PartyGuiFrame.PartyListFrame.Visible = false
  27.        
  28.     else
  29.        
  30.         script.Parent.PartyGuiFrame.CreateButton.Text = "CREATE A PARTY"
  31.        
  32.         script.Parent.PartyGuiFrame.PartyListFrame.Visible = true
  33.         script.Parent.PartyGuiFrame.CreateFrame.Visible = false
  34.     end
  35. end)
  36.  
  37.  
  38.  
  39. game.ReplicatedStorage.PartySystemRE.OnClientEvent:Connect(function(joiningParty, partyName)
  40.    
  41.     inParty = joiningParty and true or false
  42.    
  43.     if inParty then
  44.        
  45.         script.Parent.PartyGuiFrame.PartyFrame.PartyTitle.Text = partyName
  46.        
  47.         script.Parent.PartyGuiFrame.PartyFrame.Visible = true
  48.         script.Parent.PartyGuiFrame.PartyListFrame.Visible = false
  49.         script.Parent.PartyGuiFrame.CreateButton.Visible = false
  50.        
  51.         local function displayPlayers()
  52.            
  53.             for i, child in pairs(script.Parent.PartyGuiFrame.PartyFrame.PlayerList:GetChildren()) do
  54.                 if child:IsA("Frame") then
  55.                     child:Destroy()
  56.                 end
  57.             end
  58.            
  59.             for i, player in pairs(game.ReplicatedStorage.Parties[partyName].Players:GetChildren()) do
  60.                
  61.                 local template = script.PlayerTemplate:Clone()
  62.                 template.PlayerName.Text = player.Value
  63.                
  64.                 if game.Players.LocalPlayer.Name ~= game.ReplicatedStorage.Parties[partyName].Players["Party Leader"].Value and game.Players.LocalPlayer.Name ~= player.Value then
  65.                     template.LeaveButton:Destroy()
  66.                     print("e")
  67.                 else
  68.                    
  69.                     template.LeaveButton.MouseButton1Click:Connect(function()
  70.                         game.ReplicatedStorage.PartySystemRE:FireServer("kickPlayer", partyName, player)
  71.                     end)
  72.                 end
  73.                
  74.                 template.Parent = script.Parent.PartyGuiFrame.PartyFrame.PlayerList
  75.                
  76.                 script.Parent.PartyGuiFrame.PartyFrame.PlayerList.CanvasSize = UDim2.new(0, 0, 0, script.Parent.PartyGuiFrame.PartyFrame.PlayerList.UIListLayout.AbsoluteContentSize.Y)
  77.             end
  78.         end
  79.        
  80.         displayPlayers()
  81.         game.ReplicatedStorage.Parties[partyName].Players.ChildAdded:Connect(displayPlayers)
  82.         game.ReplicatedStorage.Parties[partyName].Players.ChildRemoved:Connect(displayPlayers)
  83.        
  84.     else       
  85.         script.Parent.PartyGuiFrame.PartyListFrame.Visible = true
  86.         script.Parent.PartyGuiFrame.PartyFrame.Visible = false
  87.         script.Parent.PartyGuiFrame.CreateButton.Visible = true
  88.     end
  89. end)
  90.  
  91.  
  92. script.Parent.PartyGuiFrame.PartyFrame.StartButton.MouseButton1Click:Connect(function()
  93.    
  94.     game.ReplicatedStorage.PartySystemRE:FireServer("startParty", script.Parent.PartyGuiFrame.PartyFrame.PartyTitle.Text)
  95. end)
  96.  
  97.  
  98. script.Parent.PartyGuiFrame.CreateFrame.ConfirmButton.MouseButton1Click:Connect(function()
  99.    
  100.     local partyName = script.Parent.PartyGuiFrame.CreateFrame.PartyNameBox.Text or game.Players.LocalPlayer.Name .. "'s Party"
  101.     local playerLimit = tonumber(script.Parent.PartyGuiFrame.CreateFrame.PlayerLimitBox.Text) or 10
  102.    
  103.     game.ReplicatedStorage.PartySystemRE:FireServer("createParty", partyName, playerLimit)
  104.    
  105.     creatingParty = false
  106.     script.Parent.PartyGuiFrame.CreateButton.Text = "CREATE A PARTY"
  107.     script.Parent.PartyGuiFrame.PartyListFrame.Visible = true
  108.     script.Parent.PartyGuiFrame.CreateFrame.Visible = false
  109. end)
  110.  
  111.  
  112. function updatePartyList()
  113.    
  114.     for i, child in pairs(script.Parent.PartyGuiFrame.PartyListFrame:GetChildren()) do
  115.         if child:IsA("Frame") then
  116.             child:Destroy()
  117.         end
  118.     end
  119.    
  120.     for i, party in pairs(game.ReplicatedStorage.Parties:GetChildren()) do
  121.        
  122.         local partyName = party.Name
  123.         local playerLimit = party:WaitForChild("PlayerLimit").Value
  124.         local playerCount = #party.Players:GetChildren()
  125.        
  126.         local template = script.PartyTemplate:Clone()
  127.         template.PartyName.Text = partyName
  128.         template.PlayerCount.Text = playerCount .. "/" .. playerLimit
  129.        
  130.         party.Players.ChildAdded:Connect(function() template.PlayerCount.Text = #party.Players:GetChildren() .. "/" .. playerLimit end)
  131.         party.Players.ChildRemoved:Connect(function() template.PlayerCount.Text = #party.Players:GetChildren() .. "/" .. playerLimit end)
  132.        
  133.         template.Parent = script.Parent.PartyGuiFrame.PartyListFrame
  134.        
  135.         script.Parent.PartyGuiFrame.PartyListFrame.CanvasSize = UDim2.new(0, 0, 0, script.Parent.PartyGuiFrame.PartyListFrame.UIListLayout.AbsoluteContentSize.Y)
  136.        
  137.        
  138.         template.JoinButton.MouseButton1Click:Connect(function()
  139.            
  140.             game.ReplicatedStorage.PartySystemRE:FireServer("joinParty", partyName)
  141.         end)
  142.     end
  143. end
  144.  
  145. updatePartyList()
  146. game.ReplicatedStorage.Parties.ChildAdded:Connect(updatePartyList)
  147. game.ReplicatedStorage.Parties.ChildRemoved:Connect(updatePartyList)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement