How do I make teleporting a group of people to the same location if you are in the same group/party

I am currently attempting to make a grouping system with when the leader of the group or any of the members click a button/part in the game it scans through folders to find the value of the players through a string however I cannot seem to make this work

my current script is this : local Players = game:GetService(“Players”)
script.Parent.ClickDetector.MouseClick:Connect(function(player)
local folders = game.ReplicatedStorage.Invites
local root = player.Character:FindFirstChild(“HumanoidRootPart”)
local Workspace = game:GetService(“Workspace”)
if root then
root.CFrame = CFrame.new(-2808.753, 1550.77, -3419.949)

	script.Parent.Parent.Parent["J-FIGHT"].Parent = game.ServerStorage

	game.ServerStorage["J-NOFIGHT"].Parent = game.Workspace.Areas.JudgementHall.IMPORTANT

	game.ReplicatedStorage.JudgementHall.Parent = workspace

end
for i,v in pairs(game.Players:GetPlayers()) do
	if v:IsA("Player") then
		local f = game.ReplicatedStorage.Invites:GetChildren(v.Name.."'s Group"):GetChildren()
		if f:FindFirstChild("Players") then
			for i,b in pairs(f.Players:GetChildren()) do
				if b:IsA("StringValue") then
					local realplr = game.Players[b.Value]
					local realchar = realplr.Character
					realchar.HumanoidRootPart.CFrame = root.CFrame
				end
			end
		end
	end
end

end)

The folder which it scans through is
image
image
image

The script so far attempts to scan through all these folders if to find the leader or a member then teleports all of them to the same position I’ve tried tutorials asked for scripting help from friends spent countless hours on this but cannot seem to get it to work help would be appreciated :).

I didn’t read it and didn’t know you meant LITERAL location :skull:

I’ll make an attempt to help so I don’t just delete my post and leave lol

First I’d store the players in an array instead of a folder, maybe something like:

-- Assume player1 is the party leader and player2 is a party member
local parties = {} -- Make a dictionary for each player

parties[player1] = {} -- Index the parties dictionary with the player1 object (it gets removed when they leave)

To add another player to the party you’d just do this

table.insert(parties[player1], player2)

And to search through it you’d just do this

for Index, player in pairs(parties[player1]) do 
    -- Do something to each player here (player being each player, as it will loop through them all)
end

And to set their CFrame (position was always buggy for me when it came to humanoids and their root parts)

local Destination = CFrame.new(Vector3.new(0,0,0)) -- Example
for Index, player in pairs(parties[player1]) do
    local character = player.Character

    if character then
        local rootPart = character:WaitForChild("HumanoidRootPart")
        rootPart.CFrame = Destination
      end
end

And to save you some time I think some bugs could arise like teleporting a dead player, this would solve that

for Index, player in pairs(parties[player1]) do
    local character = player.Character

    if character then
        local rootPart = character:WaitForChild("HumanoidRootPart")
        local humanoid = character:WaitForChild("Humanoid")
        if humanoid:GetState() ~= Enum.HumanoidStateType.Dead then 
            rootPart.CFrame = Destination
        end
    end
end

Or if you wanna wait 'til they respawn (this one will also handle if the player leaves or something else nobody thought of happens)

for Index, player in pairs(parties[player1]) do
    local character = player.Character
    
    local function TeleportCharacter(character)
        if character then
            local rootPart = character:WaitForChild("HumanoidRootPart")
            local humanoid = character:WaitForChild("Humanoid")

            if humanoid:GetState() ~= Enum.HumanoidStateType.Dead then 
                rootPart.CFrame = Destination
            else
                local Timeout_Tick = tick()
                repeat task.wait() until (player.Character and player.Character ~= character) or tick() - Timeout_Tick >= 10 
                if player then
                    TeleportCharacter(player.Character)
                end
            end
        end
    end
    TeleportCharacter(character)
end

Edit: There’s probably a lot of typos, I wouldn’t copy and paste, just use it to get an idea!

Hopefully that answers or at least helps your question (I admit I didn’t read the whole post, just skimmed through it, and it’s like 4am for me)

(For future reference, I recommend storing paths in variables and naming your variables more than just 1 letter lol, so u can remember what they mean later… and have it look nice for your probably strained eyes)

Thank you! I’ll check it out in a moment and I’ll hopefully get it to working as I’m pretty new with scripting so thanks!

I understand the use of arrays / tables but with my current system that would clash with stuff so I’m wondering if I could make it appropriate for my current set (apologise for not showing at the start)

script.Parent.GroupGuiFrame.Visible = false
script.Parent.GroupGuiFrame.GroupListFrame.Visible = true

local Frame = script.Parent.GroupGuiFrame
local Open = false
local PositionClosed = UDim2.new(0.5, 0,-1.5, 0)
local PositionOpen = UDim2.new(0.5, 0,0.5, 0)
local UserInputService = game:GetService(“UserInputService”)

UserInputService.InputBegan:Connect(function(keyCode)
if keyCode.KeyCode == Enum.KeyCode.P then
if Open then
Frame:TweenPosition((PositionClosed), “Out”,“Linear”,.5)
Open = false
Frame.Visible = true
task.wait(.5)
else
Open = true
Frame:TweenPosition((PositionOpen), “Out”,“Linear”,.5)
Frame.Visible = true
task.wait(.5)
end
end
end)

local creatingGroup = false
local inGroup = false

script.Parent.GroupGuiFrame.CreateButton.MouseButton1Click:Connect(function()

if inGroup then return end

creatingGroup = not creatingGroup

if creatingGroup then

	script.Parent.GroupGuiFrame.CreateButton.Text = "RETURN"

	script.Parent.GroupGuiFrame.CreateFrame.Visible = true
	script.Parent.GroupGuiFrame.GroupListFrame.Visible = false

else

	script.Parent.GroupGuiFrame.CreateButton.Text = "CREATE A GROUP"

	script.Parent.GroupGuiFrame.GroupListFrame.Visible = true
	script.Parent.GroupGuiFrame.CreateFrame.Visible = false
end

end)

game.ReplicatedStorage.InviteSystemRE.OnClientEvent:Connect(function(joiningGroup, groupName)

inGroup = joiningGroup and true or false

if inGroup then	

	script.Parent.GroupGuiFrame.GroupFrame.GroupTitle.Text = groupName

	script.Parent.GroupGuiFrame.GroupFrame.Visible = true
	script.Parent.GroupGuiFrame.GroupListFrame.Visible = false
	script.Parent.GroupGuiFrame.CreateButton.Visible = false

	local function displayPlayers()

		for i, child in pairs(script.Parent.GroupGuiFrame.GroupFrame.PlayerList:GetChildren()) do
			if child:IsA("Frame") then
				child:Destroy()
			end
		end

		for i, player in pairs(game.ReplicatedStorage.Invites[groupName].Players:GetChildren()) do

			local template = script.PlayerTemplate:Clone()
			template.PlayerName.Text = player.Value

			if game.Players.LocalPlayer.Name ~= game.ReplicatedStorage.Invites[groupName].Players["Group Leader"].Value and game.Players.LocalPlayer.Name ~= player.Value then
				template.LeaveButton:Destroy()
				print("e")
			else

				template.LeaveButton.MouseButton1Click:Connect(function()
					game.ReplicatedStorage.InviteSystemRE:FireServer("kickPlayer", groupName, player)
				end)
			end

			template.Parent = script.Parent.GroupGuiFrame.GroupFrame.PlayerList

			script.Parent.GroupGuiFrame.GroupFrame.PlayerList.CanvasSize = UDim2.new(0, 0, 0, script.Parent.GroupGuiFrame.GroupFrame.PlayerList.UIListLayout.AbsoluteContentSize.Y)
		end
	end

	displayPlayers()
	game.ReplicatedStorage.Invites[groupName].Players.ChildAdded:Connect(displayPlayers)
	game.ReplicatedStorage.Invites[groupName].Players.ChildRemoved:Connect(displayPlayers)

else		
	script.Parent.GroupGuiFrame.GroupListFrame.Visible = true
	script.Parent.GroupGuiFrame.GroupFrame.Visible = false
	script.Parent.GroupGuiFrame.CreateButton.Visible = true
end

end)

script.Parent.GroupGuiFrame.CreateFrame.ConfirmButton.MouseButton1Click:Connect(function()

local groupName = game.Players.LocalPlayer.Name .. "'s Group"
local playerLimit = tonumber(script.Parent.GroupGuiFrame.CreateFrame.PlayerLimitBox.Text) or 8

game.ReplicatedStorage.InviteSystemRE:FireServer("createGroup", groupName, playerLimit)

creatingGroup = false
script.Parent.GroupGuiFrame.CreateButton.Text = "CREATE A Group"
script.Parent.GroupGuiFrame.GroupListFrame.Visible = true
script.Parent.GroupGuiFrame.CreateFrame.Visible = false

end)

function updateGroupList()

for i, child in pairs(script.Parent.GroupGuiFrame.GroupListFrame:GetChildren()) do
	if child:IsA("Frame") then
		child:Destroy()
	end
end

for i, Group in pairs(game.ReplicatedStorage.Invites:GetChildren()) do

	local groupName = Group.Name
	local playerLimit = Group:WaitForChild("PlayerLimit").Value
	local playerCount = #Group.Players:GetChildren()

	local template = script.GroupTemplate:Clone()
	template.GroupName.Text = groupName
	template.PlayerCount.Text = playerCount .. "/" .. playerLimit

	Group.Players.ChildAdded:Connect(function() template.PlayerCount.Text = #Group.Players:GetChildren() .. "/" .. playerLimit end)
	Group.Players.ChildRemoved:Connect(function() template.PlayerCount.Text = #Group.Players:GetChildren() .. "/" .. playerLimit end)

	template.Parent = script.Parent.GroupGuiFrame.GroupListFrame

	script.Parent.GroupGuiFrame.GroupListFrame.CanvasSize = UDim2.new(0, 0, 0, script.Parent.GroupGuiFrame.GroupListFrame.UIListLayout.AbsoluteContentSize.Y)


	template.JoinButton.MouseButton1Click:Connect(function()

		game.ReplicatedStorage.InviteSystemRE:FireServer("joinGroup", groupName)
	end)
end

end

updateGroupList()
game.ReplicatedStorage.Invites.ChildAdded:Connect(updateGroupList)
game.ReplicatedStorage.Invites.ChildRemoved:Connect(updateGroupList)

I pretty much whimed this off of a tutorial as previously said I’m learning
but could there be a way to insert them into a folder in the workspace instead to use :GetChildren() or how would that work as when they are stationed in a group the gui and remote signals them into a value in replicatedstorage so if that was scanned would that be accessible to then teleport the person I’ve seen tutorials do it but my main problem is that there’s two folders which the players go in Invites.(persons party).Players again apologies,