How to make script restart after death

can someone please tell me how to make this script reset when you respawn from dying.
The script is in starter player scripts
image


local plr = game.Players.LocalPlayer
local char = plr.CharacterAdded:wait()
local hum = char:WaitForChild("Humanoid")
local rootpart,head = char:WaitForChild("HumanoidRootPart"),char:WaitForChild("Head")
game:GetService("RunService"):BindToRenderStep("CameraOffset",Enum.RenderPriority.Camera.Value-1,function()
	hum.CameraOffset = (rootpart.CFrame+Vector3.new(0,1.5,0)):pointToObjectSpace(head.CFrame.p)
end)
1 Like

Using CharacterAdded:Connect() function, it will fire everytime the character spawns or respawns.

Something like this.

local plr = game.Players.LocalPlayer

plr.CharacterAdded:Connect(function(char)
    local hum = char:WaitForChild("Humanoid")
    local rootpart,head = char:WaitForChild("HumanoidRootPart"),char:WaitForChild("Head")
    game:GetService("RunService"):BindToRenderStep("CameraOffset",Enum.RenderPriority.Camera.Value-1,function()
    	hum.CameraOffset = (rootpart.CFrame+Vector3.new(0,1.5,0)):pointToObjectSpace(head.CFrame.p)
    end)
end)
1 Like

change its parent to StarterCharacterScripts

[also: char = script.Parent]

2 Likes

just put it in startercharacterscripts

local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local rootpart,head = char:WaitForChild("HumanoidRootPart"),char:WaitForChild("Head")
game:GetService("RunService"):BindToRenderStep("CameraOffset",Enum.RenderPriority.Camera.Value-1,function()
	hum.CameraOffset = (rootpart.CFrame+Vector3.new(0,1.5,0)):pointToObjectSpace(head.CFrame.p)
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.