I cant make a player teleport

Hello! I was making a round system for my game but I can’t get players to teleport to their designated spot.

It used to work until I made the characters refresh each time a round starts/finishes.

I tried to use :WaitForChild() to no avail. However when I try to do it in the developer console it works?

Heres my code:

		for count = 1, #BuildingZones do
			local Players = PlayersService:GetPlayers()
			if Players[count] ~= nil then
				BuildingZones[count]:SetAttribute("userID", Players[count].UserId)

				table.insert(connections, Players[count].CharacterAdded:Connect(function()
					-- TP current Player to current Zone
					Players[count].Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(BuildingZones[count].Position)
					-- Clones the tools into the current Player's backpack.
					for _, tool in pairs(Tools.Building:GetChildren()) do
						local clonedTool = tool:Clone()
						clonedTool.Parent = Players[count].Backpack
					end
				end))
				Players[count]:LoadCharacter()
			end
		end

(I store all my connections in a table to be able to :Disconnect() them all more efficiently.)

6 Likes

Maybe load the character before the characteradded listener.

3 Likes

Same thing except my tools are gone.

2 Likes

Ideally, you would be setting the player’s cframe on the client but you can just add a task.wait() before you set the cframe on server. (Equivalent to Heartbeat:Wait())

2 Likes

Where should I add task.wait()? I’m not sure I understood.

2 Likes
task.wait()
Players[count].Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(BuildingZones[count].Position)
2 Likes

Oh, well in that case it still doesn’t work for me.

2 Likes
local connections = {}

for count = 1, #BuildingZones do
    local Players = PlayersService:GetPlayers()
    if Players[count] ~= nil then
        BuildingZones[count]:SetAttribute("userID", Players[count].UserId)

        local function onCharacterAppearanceLoaded(player)
            -- Disconnect the CharacterAppearanceLoaded event once it's fired to avoid unnecessary re-teleporting.
            connections[count]:Disconnect()

            local character = player.Character
            if character then
                character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(BuildingZones[count].Position)
                -- Clones the tools into the current Player's backpack.
                for _, tool in pairs(Tools.Building:GetChildren()) do
                    local clonedTool = tool:Clone()
                    clonedTool.Parent = player.Backpack
                end
            end
        end

        connections[count] = Players[count].CharacterAppearanceLoaded:Connect(function()
            onCharacterAppearanceLoaded(Players[count])
        end)

        Players[count]:LoadCharacter()
    end
end

2 Likes

Did you put LoadCharacter back to it’s original place too?

2 Likes

Yes did do that from the roblox character limit.

2 Likes

I still have the same issue. Confusing.

2 Likes

How exactly does the player not able to teleport? Try teleporting them, but have a wait line to see if the teleport work before the character is loaded.

3 Likes

No they aren’t trying to index CFrame with Position?

2 Likes

You might as well fire a remote event to the client and set the local humanoidrootpart’s cframe.

3 Likes

Oh yes you are right, sorry my bad.

2 Likes

Now it works.
I guess the CharacterAdded event is inaccurate.

2 Likes

That’s the solution, except that if I make it wait only a Heartbeat it does this:


Should I report this as a bug to Roblox?

EDIT: My avatar is floating when rhat happens

1 Like

There’s no way that’s a bug. What is your server code that physically moves the player?

2 Likes

Do you mean teleporting? Also why wouldn’t it be a bug it only happens when I skip a heartbeat.

Anyways here my code if you meant teleport:

		for count = 1, #BuildingZones do
			local Players = PlayersService:GetPlayers()
			if Players[count] ~= nil then
				BuildingZones[count]:SetAttribute("userID", Players[count].UserId)

				table.insert(connections, Players[count].CharacterAdded:Connect(function()
					task.wait() -- 2 times to bypass that weird glitch
					task.wait()
					-- Clones the tools into the current Player's backpack.
					for _, tool in pairs(Tools.Building:GetChildren()) do
						local clonedTool = tool:Clone()
						clonedTool.Parent = Players[count].Backpack
					end
					Players[count].Character:WaitForChild("HumanoidRootPart").Position = BuildingZones[count].Position
				end))
				Players[count]:LoadCharacter()
			end
		end

Well, does PivotTo fix that? I’ve never relied on changing the position of root.

1 Like