How to make a instant respawn button that TPs u to ur old CFrame?

So, Im trying to make a GUI button that when u click it u reset and get teleport back to ur old location/cframe

ive tried to make a part that has the cframe and it TPs u to the part (doesnt work)
ive tried to make a variable that stores the old cframe then TPs u to it (doesnt work)

Code:

script.Parent.MouseButton1Click:Connect(function()
	local oldCFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
	wait(.3)
	game.Players.LocalPlayer.Character.Humanoid.Health = 0
	wait(.5)
	game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = oldCFrame
end)
1 Like

One problem is your redefining the variable (local oldCFrame) each time you click. So, everytime you click it, it deletes your old CFrame and sets it to your current CFrame.

Try this:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local oldCFrame = humanoidRootPart.CFrame
script.Parent.MouseButton1Click:Connect(function()
    --This teleports the player
	humanoidRootPart.CFrame = oldCFrame
   --this sets the old position of the humanoidRootPart to the oldCFrame, thus, you can position it correctly
    oldCFrame = humanoidRootPart.CFrame
end)

TIP: It might be best, though, to use remotes to position the player rather than have it all done by the client.

doesnt work, maybe its bc my avatar is in R15

Instead of updating the CFrame relying on wait(.5) which will not ensure the character has finished loading(and therefore a PrimaryPart is set) rely on an event-based solution:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local oldCFrame = CFrame.new(0, 0, 0) --default spawn
script.Parent.MouseButton1Click:Connect(function()
	oldCFrame = Player.Character.HumanoidRootPart.CFrame
	task.wait(.3)
	Player.Character.Humanoid.Health = 0
end)

Player.CharacterAdded:Connect(function(char)
	repeat task.wait() until char.PrimaryPart
	char:SetPrimaryPartCFrame(oldCFrame)
end)
1 Like

doesnt work too lol, any other solution??

where do you have the script set?

image

the thing is u are defining the old cframe as ur current cframe lol

what does it say in the output?

Set ResetGUI.ResetOnSpawn to false.

nothing lol , theres no errors

can someone help me please i still have this problem

It’s because this is a localscript. Whenever the player clicks the button, fire a remote event which you pick up in the server with the arguments as Player and CFrame, then TP the player. Don’t teleport a player locally.

image

doesnt work

That will not work as anyone could fire the event thus overwriting the oldCFrame variable. So, someone could teleport to another players old position.

If I have time to, I’ll try to make you an entire new script