Advertisement
AyeeKingzz

PartyController

Mar 6th, 2025
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | Software | 0 0
  1. local ReplicatedStorage = game:GetService('ReplicatedStorage')
  2. local Knit = require(ReplicatedStorage.Packages.Knit)
  3.  
  4. local PartyController = Knit.CreateController { Name = "PartyController" }
  5.  
  6. local CurrentParty = nil
  7. local CurrentSelection = nil
  8.  
  9. function PartyController:KnitInit()
  10.     local Player = game:GetService('Players').LocalPlayer
  11.     local UI = Player.PlayerGui:WaitForChild('ScreenGui').UI
  12.    
  13.     local PlayerLabel = UI.ScrollingFrame.Player
  14.    
  15.     local function CreateLabel(player)
  16.         local tempPlayerLabel = PlayerLabel:Clone()
  17.         tempPlayerLabel.Text = player.Name
  18.         tempPlayerLabel.Name = player.Name
  19.         tempPlayerLabel.Visible = true
  20.         tempPlayerLabel.Parent = UI.ScrollingFrame
  21.        
  22.         tempPlayerLabel.MouseButton1Click:Connect(function()
  23.             if CurrentSelection == player then
  24.                 local currentUI = UI.ScrollingFrame:FindFirstChild(CurrentSelection.Name)
  25.                 if currentUI then currentUI.BackgroundColor3 = Color3.new(255,255,255) end
  26.                 CurrentSelection = nil
  27.                 tempPlayerLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  28.             else
  29.                 CurrentSelection = player
  30.                 tempPlayerLabel.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
  31.             end
  32.         end)
  33.     end
  34.    
  35.     --Fill in current players in game
  36.     for i, player in ipairs(game:GetService('Players'):GetChildren()) do
  37.         if player == Player then continue end
  38.         CreateLabel(player)
  39.     end
  40.    
  41.    
  42.     --Add player to list
  43.     game:GetService('Players').PlayerAdded:Connect(function(player)
  44.         CreateLabel(player)
  45.     end)
  46.    
  47.     --Remove player from list
  48.     game:GetService('Players').PlayerRemoving:Connect(function(player)
  49.         local playerLabel = UI.ScrollingFrame:FindFirstChild(player.Name)
  50.         if playerLabel then
  51.             playerLabel:Destroy()
  52.         end
  53.     end)
  54.    
  55.     PlayerLabel:Destroy()
  56. end
  57.  
  58. function PartyController:KnitStart()
  59.     local Player = game:GetService('Players').LocalPlayer
  60.     local UI = Player.PlayerGui:WaitForChild('ScreenGui').UI
  61.     local AlertUI = UI.Parent.Alert
  62.    
  63.     local PartyService = Knit.GetService('PartyService')
  64.    
  65.     UI.MiscButton.Activated:Connect(function(inputObject: InputObject)
  66.         if UI.MiscButton.Text == 'Create Party' and CurrentParty == nil then
  67.             CurrentParty = PartyService:CreateParty(Player)
  68.             UI.PartyLabel.Text = 'Party: ' .. CurrentParty.Captain.Name
  69.             UI.MiscButton.Text = 'Invite'
  70.         elseif UI.MiscButton.Text == 'Invite' and CurrentSelection and CurrentParty.Player == nil then
  71.             PartyService:InvitePlayer(CurrentParty, CurrentSelection)
  72.             CurrentParty.Player = CurrentSelection
  73.         end
  74.     end)
  75.    
  76.     UI.LeaveButton.Activated:Connect(function(inputObject: InputObject)
  77.         if CurrentParty and CurrentParty.Captain == Player then
  78.             PartyService:DisbandParty()
  79.             CurrentParty = nil
  80.             UI.PartyLabel.Text = 'Party: None'
  81.             UI.MiscButton.Text = 'Create Party'
  82.         end
  83.         if PartyService:LeaveParty() then
  84.             CurrentParty = nil
  85.             UI.PartyLabel.Text = 'Party: None'
  86.             UI.MiscButton.Text = 'Create Party'
  87.         end
  88.        
  89.        
  90.     end)
  91.    
  92.     PartyService.Invite:Connect(function(captain)
  93.         AlertUI.Alert.Text = 'ALERT: INVITE FROM CAPTAIN : ' .. captain.Name .. ' JOIN?'
  94.         AlertUI.JoinButton.Activated:Connect(function()
  95.             CurrentParty = PartyService:JoinParty(captain)
  96.             UI.PartyLabel.Text = 'Party: ' .. CurrentParty.Captain.Name
  97.             AlertUI.Visible = false
  98.         end)
  99.         AlertUI.LeaveButton.Activated:Connect(function()
  100.             PartyService:RejectInvite()
  101.             AlertUI.Visible = false
  102.         end)
  103.        
  104.         AlertUI.Visible = true
  105.     end)
  106.     PartyService.Leave:Connect(function()
  107.         CurrentParty = nil
  108.         UI.PartyLabel.Text = 'Party: None'
  109.         UI.MiscButton.Text = 'Create Party'
  110.     end)
  111. end
  112.  
  113. return PartyController
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement