Advertisement
Guest User

because sometimes people can't read devforum posts

a guest
Apr 7th, 2020
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.02 KB | None | 0 0
  1. --Server
  2.  
  3. --//Services
  4.  
  5. local Players = game:GetService("Players")
  6. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  7. local TeleportService = game:GetService("TeleportService")
  8.  
  9. --//Variables
  10.  
  11. local Assets = ReplicatedStorage:WaitForChild("Assets")
  12. local Remotes = ReplicatedStorage:WaitForChild("Remotes")
  13. local Events = Remotes.Events
  14. local Functions = Remotes.Functions
  15. local Parties = Assets.Parties
  16. local AvailableStrings = {"A","a","B","b","C","c","D","d","E","e","F","f","G","g","H","h","I","i","J","j","K","k","L","l","M","m","N","n","O",
  17. "o","P","p","Q","q","R","r","S","s","T","t","U","u","V","v","W","w","X","x","Y","y","Z","z"}
  18. local InviteQueue = {}
  19.  
  20. --//Functions
  21.  
  22. function FindAvailableSpot(player,joiner)
  23.     local Done = false
  24.     local Found = nil
  25.     if Parties:FindFirstChild(player.."'s party") ~= nil then
  26.         for i,v in pairs(Parties:FindFirstChild(player.."'s party").Party:GetChildren()) do
  27.             if v.Value == "None" and not Done then
  28.                 Done = true
  29.                 Found = i
  30.             end
  31.             if i == #Parties:FindFirstChild(player.."'s party").Party:GetChildren() and not Done then
  32.                 Done = true
  33.                 return "FULL"
  34.             elseif i == #Parties:FindFirstChild(player.."'s party").Party:GetChildren() and Done then
  35.                 return Found
  36.             end
  37.         end
  38.     end
  39. end
  40.  
  41. local function RandomKeyMaker()
  42.     local KeyTable = ""
  43.     for i,v in pairs(AvailableStrings) do
  44.         local Hello = math.random(1,2)
  45.         if Hello == 1 then
  46.             local RandomizedString = AvailableStrings[math.random(1,#AvailableStrings)]
  47.             KeyTable = KeyTable..RandomizedString
  48.         elseif Hello == 2 then
  49.             local RandomizedNumeral = math.random(1,100)
  50.             KeyTable = KeyTable..RandomizedNumeral
  51.         end
  52.         if i == #AvailableStrings then
  53.             return KeyTable
  54.         end
  55.     end
  56. end
  57.  
  58. local function ClearOriginalParty(player)
  59.     if Parties:FindFirstChild(player.UserId.."'s party") ~= nil then
  60.         Parties:FindFirstChild(player.UserId.."'s party").Party["1"].Value = "None"
  61.         for i,v in pairs(Parties:FindFirstChild(player.UserId.."'s party").Party:GetChildren()) do
  62.             if v.Value ~= "None" then
  63.                 local Player = Players:GetPlayerByUserId(tonumber(v.Value))
  64.                 if Player ~= nil then
  65.                     Events:FireClient(Player,"ENDPARTY")
  66.                     if Parties:FindFirstChild(Player.UserId.."'s party") ~= nil then
  67.                         if Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value == "None" then
  68.                             Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value = Player.UserId
  69.                         end
  70.                     end
  71.                 end
  72.             end
  73.         end
  74.     end
  75. end
  76.  
  77. local function LocatePlayer(player)
  78.     local Done = false
  79.     for i,v in pairs(Parties:GetChildren()) do
  80.         for _,Obj in pairs(v.Party:GetChildren()) do
  81.             if tonumber(Obj.Value) == player.UserId and not Done then
  82.                 Done = true
  83.                 return Obj
  84.             end
  85.         end
  86.     end
  87. end
  88.  
  89. --//Events
  90.  
  91. --player added
  92.  
  93. Players.PlayerAdded:Connect(function(player)
  94.     if Parties:FindFirstChild(player.UserId.."'s party") == nil then
  95.         local PartyFolder = Instance.new("Folder")
  96.         PartyFolder.Parent = Parties
  97.         PartyFolder.Name = player.UserId.."'s party"
  98.         local AttendeesFolder = Instance.new("Folder")
  99.         AttendeesFolder.Parent = PartyFolder
  100.         AttendeesFolder.Name = "Party"
  101.         for i = 1,4 do
  102.             if i ~= 1 then
  103.                 local X = Instance.new("StringValue")
  104.                 X.Parent = AttendeesFolder
  105.                 X.Name = i
  106.                 X.Value = "None"
  107.             else
  108.                 local X = Instance.new("StringValue")
  109.                 X.Parent = AttendeesFolder
  110.                 X.Name = i
  111.                 X.Value = player.UserId
  112.             end
  113.         end
  114.     end
  115. end)
  116.  
  117. --player removing
  118.  
  119. Players.PlayerRemoving:Connect(function(player)
  120.     local Find = LocatePlayer(player)
  121.     local Send = {}
  122.     if Find ~= nil then
  123.         Find.Value = "None"
  124.         for i,v in pairs(Find.Parent:GetChildren()) do
  125.             if v.Value ~= "None" then
  126.                 table.insert(Send,tonumber(v.Value))
  127.             end
  128.             if i == #Find.Parent:GetChildren() then
  129.                 for _,Obj in pairs(Send) do
  130.                     local Player = Players:GetPlayerByUserId(Obj)
  131.                     if Player ~= nil then
  132.                         Events:FireClient(Player,"AddAllToNewParty",{Players = Send})
  133.                     end
  134.                 end
  135.             end
  136.         end
  137.     end
  138.     if Parties:FindFirstChild(player.UserId.."'s party") ~= nil then
  139.         for i,v in pairs(Parties:FindFirstChild(player.UserId.."'s party").Party:GetChildren()) do
  140.             if v.Value ~= "None" then
  141.                 local Player = Players:GetPlayerByUserId(tonumber(v.Value))
  142.                 if Player ~= nil then
  143.                     Events:FireClient(Player,"ENDPARTY")
  144.                     if Parties:FindFirstChild(Player.UserId.."'s party") ~= nil then
  145.                         if Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value == "None" then
  146.                             Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value = Player.UserId
  147.                         end
  148.                     end
  149.                 end
  150.             end
  151.             if i == #Parties:FindFirstChild(player.UserId.."'s party").Party:GetChildren() then
  152.                 Parties:FindFirstChild(player.UserId.."'s party"):Destroy()
  153.             end
  154.         end
  155.     end
  156. end)
  157.  
  158. --functions
  159.  
  160. Functions.OnServerInvoke = function(Player,Command,ArgumentTable)
  161.     if Command == "IsReserved?" then
  162.         if game.VIPServerId ~= "" and game.VIPServerOwnerId == 0 then
  163.             return true
  164.         else
  165.             return false
  166.         end
  167.     end
  168. end
  169.  
  170. --Events
  171.  
  172. Events.OnServerEvent:Connect(function(Player,Command,ArgumentTable)
  173.     if Command == "Invite" then
  174.         local PlayerToInvite = Players:GetPlayerByUserId(ArgumentTable[1])
  175.         if PlayerToInvite ~= nil then
  176.             local Key = RandomKeyMaker()
  177.             Events:FireClient(PlayerToInvite,"Invited",{From = Player,InviteID = Key})
  178.             table.insert(InviteQueue,Key)
  179.         end
  180.     elseif Command == "AcceptInvite" then
  181.         local Key = ArgumentTable.Key
  182.         local Done = false
  183.         for i,v in pairs(InviteQueue) do
  184.             if v == Key and not Done then
  185.                 Done = not Done
  186.                 table.remove(InviteQueue,i)
  187.                 local Spot = FindAvailableSpot(ArgumentTable.From.UserId,Player)
  188.                 if Spot ~= "FULL" then
  189.                     ClearOriginalParty(Player)
  190.                     local NewParty = Parties:FindFirstChild(ArgumentTable.From.UserId.."'s party")
  191.                     local SendTable = {}
  192.                     NewParty.Party[Spot].Value = Player.UserId
  193.                     for i,v in pairs(NewParty.Party:GetChildren()) do
  194.                         if v.Value ~= "None" then
  195.                             table.insert(SendTable,v.Value)
  196.                         end
  197.                         if i == #NewParty.Party:GetChildren()then
  198.                             Events:FireClient(Player,"AddAllToNewParty",{Players = SendTable})
  199.                         end
  200.                     end
  201.                     for i,v in pairs(NewParty.Party:GetChildren()) do
  202.                         if v.Value ~= "None" then
  203.                             local vPlayer = Players:GetPlayerByUserId(tonumber(v.Value))
  204.                             Events:FireClient(vPlayer,"AddPlayerToMM",{Player = Player,PartyPlace = Spot})
  205.                         end
  206.                     end
  207.                 end
  208.             end
  209.         end
  210.     elseif Command == "Ready" then
  211.         if Parties:FindFirstChild(Player.UserId.."'s party") ~= nil then
  212.             local ReserveId = TeleportService:ReserveServer(game.PlaceId)
  213.             local PlayersToTP = {}
  214.             for i,v in pairs(Parties:FindFirstChild(Player.UserId.."'s party").Party:GetChildren()) do
  215.                 if v.Value ~= "None" then
  216.                     table.insert(PlayersToTP,Players:GetPlayerByUserId(tonumber(v.Value)))
  217.                 end
  218.                 if i == #Parties:FindFirstChild(Player.UserId.."'s party").Party:GetChildren() then
  219.                     TeleportService:TeleportToPrivateServer(game.PlaceId,ReserveId,PlayersToTP)
  220.                 end
  221.             end
  222.         end
  223.     end
  224. end)
  225.  
  226. --//Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement