Advertisement
AyeeKingzz

PartyService

Mar 6th, 2025
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | Software | 0 0
  1. local ReplicatedStorage = game:GetService('ReplicatedStorage')
  2. local Knit = require(ReplicatedStorage.Packages.Knit)
  3.  
  4. type Party = {
  5.     Captain: Player,
  6.     Player: Player
  7. }
  8.  
  9. local PartyService = Knit.CreateService {
  10.     Name = "PartyService",
  11.     Parties = {},
  12.     InviteTable = {},
  13.     Client = {
  14.         Invite = Knit.CreateSignal(),
  15.         Leave = Knit.CreateSignal(),
  16.     }
  17. }
  18.  
  19. function PartyService.Client:CreateParty(player: Player)
  20.     --Check if player in a party
  21.     for i, p in PartyService.Parties do
  22.         if p.Captain == player or p.Player == player then return end
  23.     end
  24.    
  25.     local tempParty = {
  26.         Captain = player,
  27.         Player = nil
  28.     } :: Party
  29.     table.insert(PartyService.Parties, tempParty)
  30.     return tempParty
  31. end
  32.  
  33. function PartyService.Client:DisbandParty(player: Player)
  34.     for i, p in PartyService.Parties do
  35.         if p.Captain == p.Captain then
  36.             PartyService.Parties[i] = nil
  37.             table.remove(PartyService.Parties, i)
  38.             if p.Player then PartyService.Client.Leave:Fire(p.Player) end
  39.             return true
  40.         end
  41.     end
  42. end
  43.  
  44. function PartyService.Client:LeaveParty(player:Player)
  45.     for i, p in PartyService.Parties do
  46.         if p.Player == player then
  47.             PartyService.Parties[i].Player = nil
  48.             return true
  49.         end
  50.     end
  51.     return false
  52. end
  53.  
  54. function PartyService.Client:InvitePlayer(captain: Player, party: Party, playerToInvite: Player)
  55.     if party.Captain ~= captain then return false end
  56.     if party.Player ~= nil then return false end
  57.     if table.find(PartyService.InviteTable, playerToInvite) then return false end
  58.    
  59.     --Check if playerToInvite is in a party
  60.     for i, p in PartyService.Parties do
  61.         if p.Captain == playerToInvite or p.Player == playerToInvite then return false end
  62.     end
  63.     table.insert(PartyService.InviteTable, playerToInvite)
  64.     return PartyService.Client.Invite:Fire(playerToInvite, captain)
  65. end
  66.  
  67. function PartyService.Client:RejectInvite(player: Player)
  68.     if table.find(PartyService.InviteTable, player) then
  69.         table.remove(PartyService.InviteTable, table.find(PartyService.InviteTable, player))
  70.     end
  71. end
  72.  
  73. function PartyService.Client:JoinParty(player: Player, captain: Player)
  74.     if table.find(PartyService.InviteTable, player) then
  75.         table.remove(PartyService.InviteTable, table.find(PartyService.InviteTable, player))
  76.         local tempParty = {
  77.             Captain = captain,
  78.             Player = player
  79.         } :: Party
  80.         for i, p in PartyService.Parties do
  81.             if p.Captain == tempParty.Captain then
  82.                 PartyService.Parties[i] = tempParty
  83.                 return tempParty
  84.             end
  85.         end
  86.     end
  87. end
  88.  
  89.  
  90. return PartyService
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement