Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Solved] How do I teleport a player when they join to a specific part depending on their team?

Hello,

I am making a game with 14 different white colored teams. Each team will have a personal "room" and I would like to teleport each player when they join the game to their respective rooms.

Each "room" is a model under workspace named "Room1", "Room2" etc. Under each group is a part named TelePart, which is where I want to teleport the player. Therefore, team 1 named "Room#1" corresponds to room 1 named "Room1".

Here is what I have written so far, but it doesn't seem to work...

local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(function(player)
	local RoomTeam = player.Team.Name
	local RoomNum = string.gsub(RoomTeam, "#", "")
	local Room = game:FindFirstChild(RoomNum)
	local TelePart = Room.TelePart
	
	player.CameraMaxZoomDistance = 25
	player:LoadCharacter()
	player:MoveTo(TelePart)
end)

Error : 21:47:21.554 - ServerScriptService.JoinConfig:7: attempt to index nil with 'TelePart'

Thanks in advance!

2 comments

0

your error it's because you put game:FindFIrstChild instead of game.Workspace or game:GetService("Workspace) or workspace

0

Thank you, but the "MoveTo" part is still not working...

1 answer

I found the fix, here is the final script:

local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(function(player)
	player.CameraMaxZoomDistance = 25
	player:LoadCharacter()
	
    local RoomTeam = player.Team.Name
    local RoomNum = string.gsub(RoomTeam, "#", "")
    local Room = game.Workspace:FindFirstChild(RoomNum)
    local TelePart = Room.TelePart
	
    player.Character:MoveTo(TelePart.Position)
end)

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.