HowToRoblox

PartySystemScript

Jan 1st, 2022 (edited)
2,637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.53 KB | None | 0 0
  1. local tps = game:GetService("TeleportService")
  2. local placeId = 8416623914
  3.  
  4.  
  5. game.ReplicatedStorage.PartySystemRE.OnServerEvent:Connect(function(player, instruction, value1, value2)
  6.    
  7.    
  8.     if instruction == "kickPlayer" then
  9.        
  10.         if game.ReplicatedStorage.Parties:FindFirstChild(value1) and value2.Parent == game.ReplicatedStorage.Parties[value1].Players then
  11.             if game.ReplicatedStorage.Parties[value1].Players["Party Leader"].Value == player.Name or value2.Value == player.Name then
  12.                
  13.                 if game.ReplicatedStorage.Parties[value1].Players["Party Leader"].Value == value2.Value then
  14.                    
  15.                     for i, playerInParty in pairs(game.ReplicatedStorage.Parties[value1].Players:GetChildren()) do
  16.                        
  17.                         game.ReplicatedStorage.PartySystemRE:FireClient(game.Players[playerInParty.Value], false, value1)
  18.                     end
  19.                    
  20.                     game.ReplicatedStorage.Parties[value1]:Destroy()
  21.                    
  22.                 else
  23.                    
  24.                     game.ReplicatedStorage.PartySystemRE:FireClient(game.Players[value2.Value], false, value1)
  25.                    
  26.                     value2:Destroy()
  27.                 end
  28.             end
  29.         end
  30.        
  31.        
  32.     elseif instruction == "createParty" then
  33.        
  34.         local partyName = value1 or player.Name .. "'s Party"      
  35.         partyName = game:GetService("TextService"):FilterStringAsync(partyName, player.UserId)
  36.         partyName = partyName:GetNonChatStringForBroadcastAsync()
  37.        
  38.         local newParty = Instance.new("Folder")
  39.         newParty.Name = partyName
  40.        
  41.         local players = Instance.new("Folder", newParty)
  42.         players.Name = "Players"
  43.        
  44.         local partyLeader = Instance.new("StringValue", players)
  45.         partyLeader.Name = "Party Leader"
  46.         partyLeader.Value = player.Name
  47.        
  48.         local limit = Instance.new("IntValue", newParty)
  49.         limit.Name = "PlayerLimit"
  50.         limit.Value = tonumber(value2) or 10
  51.        
  52.         newParty.Parent = game.ReplicatedStorage.Parties
  53.        
  54.         game.ReplicatedStorage.PartySystemRE:FireClient(player, true, partyName)
  55.        
  56.        
  57.     elseif instruction == "joinParty" then
  58.        
  59.         if game.ReplicatedStorage.Parties:FindFirstChild(value1) and #game.ReplicatedStorage.Parties[value1].Players:GetChildren() < game.ReplicatedStorage.Parties[value1].PlayerLimit.Value then
  60.            
  61.             local playerValue = Instance.new("StringValue")
  62.             playerValue.Value = player.Name
  63.             playerValue.Parent = game.ReplicatedStorage.Parties[value1].Players
  64.            
  65.             game.ReplicatedStorage.PartySystemRE:FireClient(player, true, value1)
  66.         end
  67.        
  68.        
  69.     elseif instruction == "startParty" then
  70.        
  71.         if game.ReplicatedStorage.Parties:FindFirstChild(value1) and game.ReplicatedStorage.Parties[value1].Players["Party Leader"].Value == player.Name then
  72.            
  73.             local playersToTP = {}
  74.            
  75.             for i, playerInParty in pairs(game.ReplicatedStorage.Parties[value1].Players:GetChildren()) do
  76.                
  77.                 table.insert(playersToTP, game.Players[playerInParty.Value])
  78.             end
  79.            
  80.            
  81.             local tpOptions = Instance.new("TeleportOptions")
  82.             tpOptions.ShouldReserveServer = true
  83.            
  84.             tps:TeleportAsync(placeId, playersToTP, tpOptions)
  85.         end
  86.     end
  87. end)
  88.  
  89.  
  90. game.Players.PlayerRemoving:Connect(function(player)
  91.    
  92.     for i, d in pairs(game.ReplicatedStorage.Parties:GetDescendants()) do
  93.        
  94.         if d:IsA("StringValue") and d.Value == player.Name then
  95.            
  96.             if d.Name == "Party Leader" then
  97.  
  98.                 for i, playerInParty in pairs(d.Parent:GetChildren()) do
  99.  
  100.                     game.ReplicatedStorage.PartySystemRE:FireClient(game.Players[playerInParty.Value], false, d.Parent.Parent.Name)
  101.                 end
  102.                
  103.                 d.Parent.Parent:Destroy()
  104.  
  105.             else
  106.  
  107.                 game.ReplicatedStorage.PartySystemRE:FireClient(player, false, d.Parent.Parent.Name)
  108.  
  109.                 d.Parent.Parent:Destroy()
  110.             end
  111.         end
  112.     end
  113. end)
Add Comment
Please, Sign In to add comment