Make a character die when he clicks on a GUI and make him reappear where he died ? [Script]

  1. What do you want to achieve? Hello, I would like to ensure that when a player clicks on a GUI then his character dies then he immediately reappears where he died. I don’t know how to accomplish this. You can find the script I made below. Thanks

  2. What is the issue?

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
script.Parent.Activated:Connect(function()
	if script.Parent.ImageColor3 == Color3.fromRGB(255, 255, 255) then
		script.Parent.ImageColor3 = Color3.fromRGB(255, 238, 0)
		char.Humanoid.Health = 0
		local cframe = char.HumanoidRootPart.CFrame
		wait(1)	
		char.HumanoidRootPart.CFrame = cframe
	end
end)

When the Player dies, it fires an event called Character.Humanoid.Died. When this event fires, save the position of the Character and when it comes to your GUI press, set the Player’s CFrame to the CFrame that you saved from your Character.Humanoid.Died event.

Additionally, if you want them to go back to the same place, I’m your script you can just do Player.CharacterAdded:Wait()

Thank you for your reply. But how do you know that the Character.Humanoid.Died function is triggered when the player clicks on the GUI? 'Cause if I put this on, it doesn’t matter how I die, I’ll reappear where I died

When you set the health to 0. Another way to do it is doing this:

GUI.MouseButton1Click:Connect(function()
    local PrevCFrame = Player.Character.HumanoidRootPart.CFrame
    Player:LoadCharacter()
    local Character = Player.Character or Player.CharacterAdded:Wait()
    Character.HumanoidRootPart.CFrame = PrevCFrame
end)
1 Like

Thank you, it’s absolutely perfect