How to make one player from each team teleport to one part

Hi.

I have this script that teleports a player to a part depending on which team they are on. But it teleports each team player to a random part and I want each player to have a dedicated part.

image

Here is the script:

local Home = workspace.AwayPart:GetChildren() 
local Away = workspace.HomePart:GetChildren()

local function Teleport(players,Location)
		 for i,player in pairs(players) do
			if player then
				local character = player.Character or player.CharacterAdded:wait()
				if character and character.Parent then
					character:PivotTo(Location[i].CFrame + Vector3.new(0,5,0)) 
				end
			end
		end
 end 

	local teams = game:GetService("Teams"):GetTeams()
	 	for _, team in pairs(teams) do


			if team.Name == "Home" then 
			Teleport(team:GetPlayers(),Home) 
		    if team.Name == "Away" then
			Teleport(team:GetPlayers(),Away) 
		
				
		
				
				
			end	
		end
    end

Any help would be appreciated! Thanks.

1 Like

Get the team the player is on and find the corresponding part for the team.

1 Like

I have already done that. Sorry but I accidently clicked send without posting the script.

Wait so is it sending the player to the other side of the field?

2 Likes

Use attributes or string values in the part so u can easily assign members with specific role.

Here is a video of what the script does. (note, it breaks after 1 time but I did not record it.

Wait so what does it do incorrectly?

2 Likes

No, but it glitches players sometimes or doesn’t teleport them to the part

2 Likes

I am sorry for asking, but how do you use attributes to store the teleport?

You can add an attribute to an object using :SetAttribute(), or you can scroll down on properties while having an object selected and change them there.
To get an attribute use :GetAttribute()
Read this if you want to know more about attributes: Instance Attributes

1 Like

Set their humanoidrootpart’s cframe to part instead of character’s.

2 Likes

is it player.character.humanoid?

No its:

local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
2 Likes

Yeah use that instead it’s less buggy

2 Likes
local character =
local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")

How would i define character then?

local character = player.Character or player.CharacterAdded:wait()
				if character and character.Parent then
					character:WaitForChild("HumanoidRootPart"):PivotTo(Location[i].CFrame + Vector3.new(0,5,0))
2 Likes

I put this in a server script, should i change it to local?