Touch button to Restore player in the same place?

Does anyone know how to make a LocalScript when you touch a Text button that respawns you in the same place where you are?

image

Save the position they died at and when the Restore button is pressed move them to that position.

You can detect when someone dies via humanoid.Died

Example code:

local character = client.Character
local position

local function characterAdded(scopedCharacter)
    character = scopedCharacter

    local humanoid = scopedCharacter:WaitForChild("Humanoid")
    local root = scopedCharacter:WaitForChild("HumanoidRootPart")

    humanoid.Died:Connect(function()
        position = root.CFrame
    end)
end

local function teleport()
    local root = character:WaitForChild("HumanoidRootPart")

    root.CFrame = position
end

client.CharacterAdded(characterAdded)
gui.MouseButton1Click:Connect(teleport)
1 Like