Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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!

0
your error it's because you put game:FindFIrstChild instead of game.Workspace or game:GetService("Workspace) or workspace PepeElToro41 132 — 4y
0
Thank you, but the "MoveTo" part is still not working... DoudGeorges 38 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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!

Ad

Answer this question