Local Script breaks after death?

My script will only work once, and then after the player dies it just will stop working.

I’ve already tried:
-Parenting the script to StarterCharacterScripts
-Making a function so that on CharacterAdded it will update the variables

LocalScript:

local RunService = game:GetService("RunService")
local RepStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local Remote = RepStorage:WaitForChild("Remotes"):WaitForChild("LookAt")

local Info = TweenInfo.new(0.1)

local Player = game.Players.LocalPlayer
local PlayerMouse = Player:GetMouse()

local Camera = workspace.CurrentCamera

local Character = Player.Character or Player.CharacterAdded:Wait()
--Old R15 code
local Head = Character:WaitForChild("Head")
--local Neck = Head:WaitForChild("Neck")

--local Torso = Character:WaitForChild("UpperTorso")
--local Waist = Torso:WaitForChild("Waist")

--New R6 stuff
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local Torso = Character:WaitForChild("Torso")
local Neck = Torso:WaitForChild("Neck")

local Arm = Character:WaitForChild("Right Arm")
local AP = Arm:WaitForChild("AlignPosition")

local Waist = HumanoidRootPart:WaitForChild("RootJoint")

local RHip = Torso:WaitForChild("Right Hip")
local LHip = Torso:WaitForChild("Left Hip")

local LHipOriginC0 = LHip.C0
local RHipOriginC0 = RHip.C0

local NeckOriginC0 = Neck.C0
local WaistOriginC0 = Waist.C0

Neck.MaxVelocity = 1/3

RunService.RenderStepped:Connect(function() 
	local CameraCFrame = Camera.CoordinateFrame

	if Torso and Head then
		local TorsoLookVector = Torso.CFrame.lookVector
		local HeadPosition = Head.CFrame.p

		if Neck and Waist then
			if Camera.CameraSubject:IsDescendantOf(Character) or Camera.CameraSubject:IsDescendantOf(Player) then
				local Point = PlayerMouse.Hit.p

				local Distance = (Head.CFrame.p - Point).magnitude
				local Difference = Head.CFrame.Y - Point.Y


				local goalNeckCFrame = CFrame.Angles(-(math.atan(Difference / Distance) * 0.5), (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 1, 0)
				Neck.C0 = Neck.C0:lerp(goalNeckCFrame*NeckOriginC0, 0.5 / 2).Rotation + NeckOriginC0.Position

				local xAxisWaistRotation = -(math.atan(Difference / Distance) * 0.5)
				local yAxisWaistRotation = (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 0.5
				local rotationWaistCFrame = CFrame.Angles(xAxisWaistRotation, yAxisWaistRotation, 0)
				local goalWaistCFrame = rotationWaistCFrame*WaistOriginC0
				Waist.C0 = Waist.C0:lerp(goalWaistCFrame, 0.5 / 2).Rotation + WaistOriginC0.Position


				local currentLegCounterCFrame = Waist.C0*WaistOriginC0:Inverse()

				local legsCounterCFrame = currentLegCounterCFrame:Inverse()

				RHip.C0 =  legsCounterCFrame*RHipOriginC0
				LHip.C0 = legsCounterCFrame*LHipOriginC0
				
				AP.Position = Arm.Position + Camera.CFrame.LookVector * 1
				--AO.CFrame = CFrame.new(Arm.Position, Arm.Position + Camera.CFrame.LookVector)
				
				Remote:FireServer(NeckOriginC0, Neck, goalNeckCFrame, WaistOriginC0, Waist, goalWaistCFrame, currentLegCounterCFrame, legsCounterCFrame, RHip, RHipOriginC0, LHip, LHipOriginC0)
			end
		end
	end	
end)

Remote.OnClientEvent:Connect(function(NeckOriginC02, Neck2, goalNeckCFrame2, WaistOriginC02, Waist2, goalWaistCFrame2, currentLegCounterCFrame2, legsCounterCFrame2, RHip2, RHipOriginC02, LHip2, LHipOriginC02)
	TweenService:Create(Neck2, Info, {C0 = Neck2.C0:lerp(goalNeckCFrame2*NeckOriginC02, 0.5 / 2).Rotation + NeckOriginC02.Position}):Play()
	--Neck2.C0 = Neck2.C0:lerp(goalNeckCFrame2*NeckOriginC02, 0.5 / 2).Rotation + NeckOriginC02.Position
	TweenService:Create(Waist2, Info, {C0 = Waist2.C0:lerp(goalWaistCFrame2, 0.5 / 2).Rotation + WaistOriginC02.Position}):Play()
	--Waist2.C0 = Waist2.C0:lerp(goalWaistCFrame2, 0.5 / 2).Rotation + WaistOriginC02.Position
	TweenService:Create(RHip2, Info, {C0 = legsCounterCFrame2*RHipOriginC02}):Play()
	--RHip2.C0 =  legsCounterCFrame2*RHipOriginC02
	TweenService:Create(LHip2, Info, {C0 = legsCounterCFrame2*LHipOriginC02}):Play()
	--LHip2.C0 = legsCounterCFrame2*LHipOriginC02
end)
1 Like

i think if you parent it into StarterCharacterScript it should work

try put print(“hello”) at the top to check it is run again after character respawn

You haven’t stated what about the script stops working. It would help to know more about where the script currently is, and how you attempted to use CharacterAdded

Yes, I’ve attempted to use CharacterAdded, and also it’s just that the entire script just stops working.

I used CharacterAdded by making it that on LocalPlayer.CharactedAdded, the Variables like HUmanoid, Waist, etc. are changed to belong to what is supposed to be the new character model.

Hmm, it did print “hello” on respawn, let me put more print statements.

I managed to fix it, just by deleting an if statement, thanks for the help.