Help with Party

Hello! I have been working with some people and they gave me this Party System Teleport, It works really well but it has some flaws. For Example, If the person gets invited 2 times then it will show that they joined, 2 times and it prevents it from teleporting.

Local Script on Frame:

--//sounds
local invitesound = workspace.Invite
local InviteSent = workspace.InviteSent
local JoinSound = workspace.JoinSound
local Playing = workspace.JoiningGame
--//Services

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables

local Player = Players.LocalPlayer
local Assets = ReplicatedStorage:WaitForChild("Assets")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Parties = Assets:WaitForChild("Parties")
local MyParty = Parties:WaitForChild(Player.UserId.."'s party")
local Events = Remotes.Events
local Functions = Remotes.Functions
local UI = Assets.UI
local GUI = script.Parent
local L = script.Parent.Parent.L
local Main = GUI:WaitForChild("Main")
local Lobby = L.BattleRoyale.Lobbyq.Modes.BackgroundE

local Invite = Main.Invite
local InviteCoolDown = false

--//Functions

local function CheckForPlayersYouMissed()
	for i,player in pairs(Players:GetPlayers()) do
		if Invite:FindFirstChild(player.UserId) == nil and player ~= Player then
			local Template = UI.InviteTemplate:Clone()
			Template.Parent = Invite
			Template.Name = player.UserId
			Template.Playernamet.Text = player.Name
			Template.Image.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..player.UserId.."&width=420&height=420&format=png"
			Template.Invite.MouseButton1Click:Connect(function()
				InviteSent:Play()
				script.Parent.Parent.L.Frame.Visible = true
				script.Parent.Parent.L.Frame.Party.Text = "Invite Sent"
				script.Parent.Parent.L.Frame.Invited.Text = "sent Invite too,"..player.name
				wait(1)
				script.Parent.Parent.L.Frame.Visible = false
				if not InviteCoolDown then
					InviteCoolDown = not InviteCoolDown
					Events:FireServer("Invite",{tonumber(Template.Name)}) -- tell the server they want to invite the player
					wait(10)
					InviteCoolDown = not InviteCoolDown
				end
			end)
		end
	end
end

local function FindInTable(index,tbl)
	for i,v in pairs(tbl) do
		if i == index then
			return v
		end
	end
end

--//Events
Players.PlayerAdded:Connect(function(player)
	if Invite:FindFirstChild(player.UserId) == nil and player ~= Player then
		local Template = UI.InviteTemplate:Clone()
		Template.Parent = Invite
		Template.Name = player.UserId
		Template.Playernamet.Text = player.Name
		Template.Image.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..player.UserId.."&width=420&height=420&format=png"
		Template.Invite.MouseButton1Click:Connect(function()
			InviteSent:Play()
			script.Parent.Parent.L.Frame.Visible = true
			script.Parent.Parent.L.Frame.Party.Text = "Invite Sent"
			script.Parent.Parent.L.Frame.Invited.Text = "sent Invite too,"..player.name
			wait(1)
			script.Parent.Parent.L.Frame.Visible = false
			if not InviteCoolDown then
				InviteCoolDown = not InviteCoolDown
				Events:FireServer("Invite",{tonumber(Template.Name)}) -- tell the server they want to invite the player
				wait(4)
				InviteCoolDown = not InviteCoolDown
			end
		end)
	end
end)

Players.PlayerRemoving:Connect(function(player)
	if Invite:FindFirstChild(player.UserId) ~= nil and player ~= Player then
		Invite:FindFirstChild(player.UserId):Destroy() -- remove their stuff since they left
		script.Parent.Parent.L.Frame.Visible = true
		script.Parent.Parent.L.Frame.Party.Text = "Player Left The Party"
		script.Parent.Parent.L.Frame.Invited.Text = player.name.."Has left the Party"
		wait(1)
		script.Parent.Parent.L.Frame.Visible = false
	end
end)

Functions.OnClientInvoke = function(Command,ArgumentTable)
	
end

Events.OnClientEvent:Connect(function(Command,ArgumentTable)
	if Command == "AddPlayerToMM" then
		local AddPlayer = ArgumentTable.Player
		local PartyPlace = ArgumentTable.PartyPlace
		JoinSound:Play()
		Main.Party:FindFirstChild("Player"..PartyPlace).Player.Text = AddPlayer.Name
		Main.Party:FindFirstChild("Player"..PartyPlace).Icon.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..AddPlayer.UserId.."&width=420&height=420&format=png"
		script.Parent.Parent.L.Frame.Visible = true
		script.Parent.Parent.L.Frame.Party.Text = "PlayerJoined"
		script.Parent.Parent.L.Frame.Invited.Text = AddPlayer.Name.."Joined the party"
		wait(1)
		script.Parent.Parent.L.Frame.Visible = false
		if AddPlayer == Player then
			if PartyPlace == 1 then
				Main.Ready.Visible = true
				script.Parent.Parent.L.BattleRoyale.Lobbyq.Modes.BackgroundE.Visible = true
				Main.InviteFriends.Visible = true
				Main.Open.Visible = true
			else
				script.Parent.Ding:play()
				Main.Ready.Visible = false
				--Main.Zombies.Visible = false
				script.Parent.Parent.L.BattleRoyale.Lobbyq.Modes.BackgroundE.Visible = false
				--Main.Invited.Fake = true
				Main.InviteFriends.Visible = false
				Main.Open.Visible = false
				Main.Hide.Visible = false
				Main.Invite.Visible = false
				Main.InviteOut.Visible = false
				if Main.Party.Player1.Player.Text == Player.Name then
					Main.Ready.Visible = true
				end
			end
		end
	elseif Command == "ENDPARTY" then
		for i,v in pairs(Main.Party:GetChildren()) do
			if v.Name ~= "Player1" then
				v.Icon.Image = "rbxassetid://234368843"
				v.Player.Text = "PlayerName"
			else
				v.Player.Text = Player.Name
				v.Icon.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"
			end
			
			
			
		end
		script.Parent.Parent.L.Frame.Visible = true
		script.Parent.Parent.L.Frame.Party.Text = "PlayerLeft"
		script.Parent.Parent.L.Frame.Invited.Text = Player.Name.."Left the party"
		wait(1)
		script.Parent.Parent.L.Frame.Visible = false
		script.Parent.error:play()
		script.Parent.Parent.L.BattleRoyale.Lobbyq.Modes.BackgroundE.Visible = true
		Main.InviteFriends.Visible = true
		Main.Open.Visible = true
		--Main.Invited = true
		--Main.Zombies.Visible = true
		Main.Ready.Visible = true
		--Main.Invited.Fake = false
		Main.BadNews.Visible = true
		wait(string.len(Main.BadNews.Text)/20)
		Main.BadNews.Visible = false
	elseif Command == "Invited" then
		local PlayerFrom = ArgumentTable.From
		Main.Invited.Visible = true
		Main.Invited.Title.Text = PlayerFrom.Name
		Main.Invited.ImageLabel.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..PlayerFrom.UserId.."&width=420&height=420&format=png"
		script.Parent.Parent.L.Frame.Visible = true
		script.Parent.Parent.L.Frame.Party.Text = "Party Invite"
		script.Parent.Parent.L.Frame.Invited.Text = PlayerFrom.Name.." has invited you to a party"
		invitesound:Play()
wait(1)
		script.Parent.Parent.L.Frame.Visible = false

		Main.Invited.Yes.MouseButton1Click:Connect(function()
			script.Parent.Parent.L.Frame.Visible = false
			Main.Invited.Visible = false
			Events:FireServer("AcceptInvite",{From = PlayerFrom,Key = ArgumentTable.InviteID})
		end)
		Main.Invited.No.MouseButton1Click:Connect(function()
			script.Parent.Parent.L.Frame.Visible = false
			Main.Invited.Visible = false
			Events:FireServer("DeclineInvite",{From = PlayerFrom,Key = ArgumentTable.InviteID})
		end)
	elseif Command == "AddAllToNewParty" then
		local PlayersTable = ArgumentTable.Players
		for i,v in pairs(Main.Party:GetChildren()) do
			local Find = FindInTable(i,PlayersTable)
			if Find ~= nil then
				if Players:GetPlayerByUserId(tonumber(Find)) == Player then
					if i == 1 then
						Main.Ready.Visible = true
						--Main.Zombies = true
						JoinSound:Play()
						
					else
						Main.Ready.Visible = false
						Lobby.Visible = false
						Main.Zombies.Visible = false
			

					end
				end
			end
			if Find ~= nil then
				v.Player.Text = Players:GetPlayerByUserId(tonumber(Find)).Name
				v.Icon.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..Find.."&width=420&height=420&format=png"
			else
				v.Icon.Image = "rbxassetid://234368843"
				v.Player.Text = "PlayerName"
			end
		end
	end
end)


Main.Zombies.MouseButton1Click:Connect(function(person)
	script.Parent.Parent.Loading.Enabled = true
	script.Parent.Parent.L.Enabled = false
	script.Parent.Parent.Party.Enabled = false

	Events:FireServer("Zombies")
Playing:Play() 
end)

Main.Ready.MouseButton1Click:Connect(function()
	script.Parent.Parent.Loading.Enabled = true
	script.Parent.Parent.L.Enabled = false
	script.Parent.Parent.Party.Enabled = false

	Events:FireServer("Ready")
	Playing:Play() 
end)


--//Main

Main.Ready.Visible = true


CheckForPlayersYouMissed()

if MyParty ~= nil then
	if tonumber(MyParty.Party["1"].Value) == Player.UserId then
		Main.Party.Player1.Player.Text = Player.Name
		Main.Party.Player1.Icon.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"
	end
end

local CheckIfServerIsReserved = Functions:InvokeServer("IsReserved?")

if CheckIfServerIsReserved then
	Main.Visible = false
end

Server Script Service Script:

--//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 ---Public with squad

		if Parties:FindFirstChild(Player.UserId.."'s party") ~= nil then			
			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
					print("Yay... Teleporting")
					TeleportService:TeleportPartyAsync(3183203159,PlayersToTP)
				else
					print("bruh...") 
				end
			end
		end
		------------------------------------------------------------------------------------------------------------------------------

		--one part
	elseif Command == "Zombies" then ---Public with squad

		if Parties:FindFirstChild(Player.UserId.."'s party") ~= nil then			
			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
					print("Yay... Teleporting")
					TeleportService:TeleportPartyAsync(5553335287,PlayersToTP)
				else
					print("bruh...")
				end
			end
		end
		-----

end
end)
--//Main
3 Likes

I’m not sure I understood because it lacks information and I’m not too keen to read the whole script but I believe that you could use Players.PlayerRemoving to reset your counter when the player leaves your game

Sorry, What I meant was that if a player invites the same player twice, as in clicks the invite twice it will appear as they joined two times as in taking 2 spots.