Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Server
- --//Services
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local TeleportService = game:GetService("TeleportService")
- --//Variables
- local Assets = ReplicatedStorage:WaitForChild("Assets")
- local Remotes = ReplicatedStorage:WaitForChild("Remotes")
- local Events = Remotes.Events
- local Functions = Remotes.Functions
- local Parties = Assets.Parties
- 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",
- "o","P","p","Q","q","R","r","S","s","T","t","U","u","V","v","W","w","X","x","Y","y","Z","z"}
- local InviteQueue = {}
- --//Functions
- function FindAvailableSpot(player,joiner)
- local Done = false
- local Found = nil
- if Parties:FindFirstChild(player.."'s party") ~= nil then
- for i,v in pairs(Parties:FindFirstChild(player.."'s party").Party:GetChildren()) do
- if v.Value == "None" and not Done then
- Done = true
- Found = i
- end
- if i == #Parties:FindFirstChild(player.."'s party").Party:GetChildren() and not Done then
- Done = true
- return "FULL"
- elseif i == #Parties:FindFirstChild(player.."'s party").Party:GetChildren() and Done then
- return Found
- end
- end
- end
- end
- local function RandomKeyMaker()
- local KeyTable = ""
- for i,v in pairs(AvailableStrings) do
- local Hello = math.random(1,2)
- if Hello == 1 then
- local RandomizedString = AvailableStrings[math.random(1,#AvailableStrings)]
- KeyTable = KeyTable..RandomizedString
- elseif Hello == 2 then
- local RandomizedNumeral = math.random(1,100)
- KeyTable = KeyTable..RandomizedNumeral
- end
- if i == #AvailableStrings then
- return KeyTable
- end
- end
- end
- local function ClearOriginalParty(player)
- if Parties:FindFirstChild(player.UserId.."'s party") ~= nil then
- Parties:FindFirstChild(player.UserId.."'s party").Party["1"].Value = "None"
- for i,v in pairs(Parties:FindFirstChild(player.UserId.."'s party").Party:GetChildren()) do
- if v.Value ~= "None" then
- local Player = Players:GetPlayerByUserId(tonumber(v.Value))
- if Player ~= nil then
- Events:FireClient(Player,"ENDPARTY")
- if Parties:FindFirstChild(Player.UserId.."'s party") ~= nil then
- if Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value == "None" then
- Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value = Player.UserId
- end
- end
- end
- end
- end
- end
- end
- local function LocatePlayer(player)
- local Done = false
- for i,v in pairs(Parties:GetChildren()) do
- for _,Obj in pairs(v.Party:GetChildren()) do
- if tonumber(Obj.Value) == player.UserId and not Done then
- Done = true
- return Obj
- end
- end
- end
- end
- --//Events
- --player added
- Players.PlayerAdded:Connect(function(player)
- if Parties:FindFirstChild(player.UserId.."'s party") == nil then
- local PartyFolder = Instance.new("Folder")
- PartyFolder.Parent = Parties
- PartyFolder.Name = player.UserId.."'s party"
- local AttendeesFolder = Instance.new("Folder")
- AttendeesFolder.Parent = PartyFolder
- AttendeesFolder.Name = "Party"
- for i = 1,4 do
- if i ~= 1 then
- local X = Instance.new("StringValue")
- X.Parent = AttendeesFolder
- X.Name = i
- X.Value = "None"
- else
- local X = Instance.new("StringValue")
- X.Parent = AttendeesFolder
- X.Name = i
- X.Value = player.UserId
- end
- end
- end
- end)
- --player removing
- Players.PlayerRemoving:Connect(function(player)
- local Find = LocatePlayer(player)
- local Send = {}
- if Find ~= nil then
- Find.Value = "None"
- for i,v in pairs(Find.Parent:GetChildren()) do
- if v.Value ~= "None" then
- table.insert(Send,tonumber(v.Value))
- end
- if i == #Find.Parent:GetChildren() then
- for _,Obj in pairs(Send) do
- local Player = Players:GetPlayerByUserId(Obj)
- if Player ~= nil then
- Events:FireClient(Player,"AddAllToNewParty",{Players = Send})
- end
- end
- end
- end
- end
- if Parties:FindFirstChild(player.UserId.."'s party") ~= nil then
- for i,v in pairs(Parties:FindFirstChild(player.UserId.."'s party").Party:GetChildren()) do
- if v.Value ~= "None" then
- local Player = Players:GetPlayerByUserId(tonumber(v.Value))
- if Player ~= nil then
- Events:FireClient(Player,"ENDPARTY")
- if Parties:FindFirstChild(Player.UserId.."'s party") ~= nil then
- if Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value == "None" then
- Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value = Player.UserId
- end
- end
- end
- end
- if i == #Parties:FindFirstChild(player.UserId.."'s party").Party:GetChildren() then
- Parties:FindFirstChild(player.UserId.."'s party"):Destroy()
- end
- end
- end
- end)
- --functions
- Functions.OnServerInvoke = function(Player,Command,ArgumentTable)
- if Command == "IsReserved?" then
- if game.VIPServerId ~= "" and game.VIPServerOwnerId == 0 then
- return true
- else
- return false
- end
- end
- end
- --Events
- Events.OnServerEvent:Connect(function(Player,Command,ArgumentTable)
- if Command == "Invite" then
- local PlayerToInvite = Players:GetPlayerByUserId(ArgumentTable[1])
- if PlayerToInvite ~= nil then
- local Key = RandomKeyMaker()
- Events:FireClient(PlayerToInvite,"Invited",{From = Player,InviteID = Key})
- table.insert(InviteQueue,Key)
- end
- elseif Command == "AcceptInvite" then
- local Key = ArgumentTable.Key
- local Done = false
- for i,v in pairs(InviteQueue) do
- if v == Key and not Done then
- Done = not Done
- table.remove(InviteQueue,i)
- local Spot = FindAvailableSpot(ArgumentTable.From.UserId,Player)
- if Spot ~= "FULL" then
- ClearOriginalParty(Player)
- local NewParty = Parties:FindFirstChild(ArgumentTable.From.UserId.."'s party")
- local SendTable = {}
- NewParty.Party[Spot].Value = Player.UserId
- for i,v in pairs(NewParty.Party:GetChildren()) do
- if v.Value ~= "None" then
- table.insert(SendTable,v.Value)
- end
- if i == #NewParty.Party:GetChildren()then
- Events:FireClient(Player,"AddAllToNewParty",{Players = SendTable})
- end
- end
- for i,v in pairs(NewParty.Party:GetChildren()) do
- if v.Value ~= "None" then
- local vPlayer = Players:GetPlayerByUserId(tonumber(v.Value))
- Events:FireClient(vPlayer,"AddPlayerToMM",{Player = Player,PartyPlace = Spot})
- end
- end
- end
- end
- end
- elseif Command == "Ready" then
- if Parties:FindFirstChild(Player.UserId.."'s party") ~= nil then
- local ReserveId = TeleportService:ReserveServer(game.PlaceId)
- local PlayersToTP = {}
- for i,v in pairs(Parties:FindFirstChild(Player.UserId.."'s party").Party:GetChildren()) do
- if v.Value ~= "None" then
- table.insert(PlayersToTP,Players:GetPlayerByUserId(tonumber(v.Value)))
- end
- if i == #Parties:FindFirstChild(Player.UserId.."'s party").Party:GetChildren() then
- TeleportService:TeleportToPrivateServer(game.PlaceId,ReserveId,PlayersToTP)
- end
- end
- end
- end
- end)
- --//Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement