How would I teleport ROBLOX players to their original position after rejoining by command?

game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, game.JobId, sender, nil, playerPosition,script.ScreenGui)

How would I teleport ROBLOX players to their original position after rejoining by command?

I know that you can send data after rejoining

commands.rejoin = function(sender, arguments)
    -- Get the player's current position
    local player = sender
    local playerPosition = player.Character and player.Character.HumanoidRootPart and
                               player.Character.HumanoidRootPart.Position
    if not playerPosition then
        return
    end

    -- Save the player's position to the data store
    local success, err = pcall(function()
        playerDataStore:SetAsync(player.UserId .. "_position", playerPosition)
    end)
    if not success then
        warn("Failed to save player position:", err)
    end

    -- Rejoin the exact same server (by using JobID)
    game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, game.JobId, sender, nil, playerPosition,script.ScreenGui)
    sender.CharacterAdded:Wait()
    local humanoidRootPart = sender.Character:FindFirstChild("HumanoidRootPart")
    if humanoidRootPart then
        humanoidRootPart.Position = playerPosition
    end
end

The above code explains what I wanna accomplish as the above obviously does not work with the like set position as you have to do it in some way I do not know how to.

1 Like

Set the CFrame of the HumanoidRootPart to the Position provided:

humanoidRootPart.CFrame = CFrame.new(playerPosition)