Local Scripts stops working after Player dies?

So, i have made 3 local scripts for the Player’s Character, they all work completely fine, but once you die they stop working, but i don’t understand why ! They are all located in StarterCharacterScripts, and i made sure to define the Player’s Character using local Character = Player.Character or Player.CharacterAdded:Wait() . There are no errors/warnings in the Output. Here are the scripts :

Triple Jump Script:

--//Variables//--
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
local Step = Root:WaitForChild("StepTJ")
local Whoosh = Root:WaitForChild("WhooshTJ")
local Jump1 = script:WaitForChild("Jump 1")
local Jump2 = script:WaitForChild("Jump 2")
local Jump3 = script:WaitForChild("Jump 3")
local JumpAnim1 = Humanoid:LoadAnimation(Jump1)
local JumpAnim2 = Humanoid:LoadAnimation(Jump2)
local JumpAnim3 = Humanoid:LoadAnimation(Jump3)
JumpAnim1.Priority = Enum.AnimationPriority.Action3
JumpAnim2.Priority = Enum.AnimationPriority.Action3
JumpAnim3.Priority = Enum.AnimationPriority.Action3
----------------------------------------------------
Jump = 0
isJumping = false
isFalling = false
-------------------------------------------------------
--//Functions//--
function onJump(Val)
	isJumping = Val
	if isJumping and Jump > 1 and Jump < 3 then
		Humanoid.JumpPower = 50
		Jump = 3
		JumpAnim3:Play()
		JumpAnim3:AdjustSpeed(1.75)
		Step:Play()
		Whoosh:Play()
		Root.Velocity = Root.Velocity + Vector3.new(0, 95, 0)
		task.wait(0.2)
		Whoosh:Play()
		task.wait(0.35)
		Whoosh:Play()
		Jump = 0
	elseif isJumping and Jump > 0 and Jump < 2 then
		Humanoid.JumpPower = 50
		Jump = 2
		JumpAnim2:Play()
		JumpAnim2:AdjustSpeed(0.5)
		Step:Play()
		Root.Velocity = Root.Velocity + Vector3.new(0, 75, 0)
	elseif isJumping and Jump < 1 then
		Humanoid.JumpPower = 50
		Jump = 1
		JumpAnim1:Play()
		JumpAnim1:AdjustSpeed(0.75)
		Step:Play()
	end
end
---------------------------------------------
function onFall(Val)
	isFalling = Val
	if not Val then
		task.wait(0.25)
		if Jump > 0 and not isFalling then
			Jump = 0
		end
	end
end
--//Connections//--
Humanoid.Jumping:Connect(onJump)
Humanoid.FreeFalling:Connect(onFall)

Walking Effects Script :

--//Variables//--
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
local Footstep = Root:WaitForChild("SteppingSound")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
----------------------------------------------------
--//Function//--
function onHumanoidRunning(Speed)
	if Speed > 6 then
		Footstep.Playing = true
	else
		Footstep.Playing = false
	end
end
----------------------------------------------------
function onHumanoidNotRunning()
	Footstep.Playing = false
end
--//Connections//--
Humanoid.Running:Connect(onHumanoidRunning)
Humanoid.Jumping:Connect(onHumanoidNotRunning)
Humanoid.FreeFalling:Connect(onHumanoidNotRunning)
Humanoid.Swimming:Connect(onHumanoidNotRunning)

Landing Effects Script :

--//Variables//--
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
local Landing = script:WaitForChild("Landing")
local LandingAnim = Humanoid:LoadAnimation(Landing)
local LandingSound = Root:WaitForChild("LandingSound")
--//Function//--
function onHumanoidStateChanged(_, State)
	if State == Enum.HumanoidStateType.Landed then
		LandingAnim:AdjustSpeed(5)
		LandingAnim:Play()
		LandingSound:Play()
		---------------------------------------------------
		local CloudPart = Instance.new("Part", Character)
		CloudPart.Anchored = true
		CloudPart.CanCollide = false
		CloudPart.CanTouch = false
		CloudPart.Position = Root.Position - Vector3.new(0, 2.5, 0)
		CloudPart.Size = Vector3.new(2.5, 2.5, 2.5)
		CloudPart.Material = Enum.Material.Neon
		CloudPart.BrickColor = BrickColor.new(255, 255, 255)
		--------------------------------------------------------
		local CloudMesh = Instance.new("SpecialMesh", CloudPart)
		CloudMesh.Scale = Vector3.new(0.05, 0.025, 0.05)
		CloudMesh.MeshId = "rbxassetid://11978515144"
		--------------------------------------------------------
		local TweenService = game:GetService("TweenService")
		local TweenInfo1 = TweenInfo.new(0.25, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
		local TweenSize = TweenService:Create(CloudMesh, TweenInfo1, {Scale = Vector3.new(0.15, 0.025, 0.15)})
		local TweenTransparency = TweenService:Create(CloudPart, TweenInfo1, {Transparency = 1})
		TweenSize:Play()
		TweenTransparency:Play()
		task.wait(0.3)
		CloudPart:Destroy()
	end
end
--//Connection//--
Humanoid.StateChanged:Connect(onHumanoidStateChanged)

I seriously have no idea what could be causing this. Please help!

5 Likes

Hmmm maybe you can just put local character = player.Character because sometimes ‘or’ statements can cause loops and maybe try changing local player to: game.Players.LocalPlayer

Though im not sure it might help (im also a beginner)

That didn’t change anything sadly.

when player character dies it sets parent to nil which breaks script in your case. I had same problem before, you can either prevent player from dying or prevent running your functions when character.Parent = nil

1 Like

So in the functions i need to add like if Character = nil then return end ?

yes, that should resolve your problem

where exactly do i put it in for each script?

The StarterCharacterScripts class stores scripts to be parented in a player’s Player.Character, when they spawn. Unlike scripts stored in the PlayerScripts folder, these scripts will not persist when the player respawns.

I would recommend just using StarterPlayerScripts as scripts in there work even after a player respawns.

I tried that already, and it didn’t work unfortunately.

So all the scripts are in StarterPlayerScripts and it still doesn’t work? Try adding a print statement at the start of each script to see if it runs.

It prints when i start the game, but when i die it doesn’t print anything?

Can you send a screenshot of where the scripts are located?

Here it is :

Capture d’écran (246)

Ignore the Coin & ItemBlock system scripts.

Once the character dies, your variable would be replace by nil, so you would have to redefine the character whenever the player dies. To do this, you could check when the Humanoid is killed, and redefine your variable when the event is triggered.

This event fires when the Humanoiddies, usually when Humanoid.Healthreaches 0. This could be caused either by disconnecting their head from their Humanoid.Torso, or directly setting the health property.

This event only fires if the Humanoidis a descendant of the Workspace. If the Dead HumanoidStateType is disabled it will not fire.

Do i need to put it in a PlayerAdded/CharacterAdded function tho?

Actually, you should just use player.CharacterAdded, as that event fires whenever the character spawns (or respawns).

Player.CharacterAdded = Didn’t work, says that WaitForChild(“Humanoid”) isn’t a valid member of RBXScriptSignal.

Player.CharacterAdded:Wait() = Doesn’t work, but no errors.

1 Like

Sorry, I made a mistake earlier.

You can either use StarterCharacterScripts, and everything in that script will re-run right when the character is added or dies, or do the following in a script in StarterPlayerScripts to make only certain things in the script re-run:

local player = game.Players.LocalPlayer

player.CharacterAdded:Connect(function()
	print(player.Character)
end)

If you want to try doing it with StarterPlayerScripts (probably more efficient), use the script above and set your variable to player.Character whenever that script runs (make sure to declare it outside of that function, as otherwise you won’t be able to access it out of that function’s scope).

I’m a bit confused, i need to add a Player.CharacterAdded event with all the code in it?

No, you would just update the character variable within that event.