Script stops when I die

Hello !

So, like the title says, the script stops when I die. I recently installed a footstep system in ServerScriptService. In the output, I saw that it’s from a script called running. So here are the configuration and scripts into my workspace ;

image

I have to precise that i’m highly limited into scripting and that I want to fix it very fast. I know that I can copy the script maybe and destroy the current one when I die, but I don’t know how to do it and where to place it…

“Footstep” script :

--poner en ServerScriptServicie o Workspace

--[[
	Foorsteps para R6 y R15....
	este script nosirve mucho para filtering enabled por lo cual no es recomendado usar este 
	script para places con FE
	--CREDITOS: iiMAYK
	--CREDOTOS: Xx_andresXx
--]]


game.Players.PlayerAdded:connect(function(p)
	p.CharacterAdded:connect(function(c)
		local x = script:GetChildren()
		if c:FindFirstChild('Sound') then
			c.Sound:Destroy()
		end
		for i = 1, #x do
			if x[i]:IsA('Script') then
				local e = x[i]:Clone()
				e.Parent = c.HumanoidRootPart
				e.Disabled = false
			else
				x[i]:Clone().Parent = c.HumanoidRootPart
			end
		end
		local r = c.Head:GetChildren()
		for i = 1,#r do
			if r[i]:IsA('Sound') then
				r[i]:Destroy()
			end
		end
	end)
end)

“Runing” script : (I’m really sure that the problem comes from here)

local running = true;
local Connection = nil;
local Humanoid = script.Parent.Parent.Humanoid

function WhileRunning() 
	if script.Parent.Materials.Value == "Grass" then
		script.Parent.Grass:Play()
	elseif script.Parent.Materials.Value == "Water" then
		script.Parent.Splash:Play()
	elseif script.Parent.Materials.Value == "Wood" then
		script.Parent.Wood:Play()
	elseif script.Parent.Materials.Value == "Ice" then
		script.Parent.Ice:Play()
	elseif script.Parent.Materials.Value == "Plastic" then
		script.Parent.Plastic:Play()
	elseif script.Parent.Materials.Value == "WoodPlanks" then
		script.Parent.WoodPlanks:Play()
	elseif script.Parent.Materials.Value == "Cobblestone" then
		script.Parent.Cobblestone:Play()
	elseif script.Parent.Materials.Value == "Fabric" then
		script.Parent.Fabric:Play()
	elseif script.Parent.Materials.Value == "CMetal" then
		script.Parent.Diamond:Play()
	elseif script.Parent.Materials.Value == "Metal" then
		script.Parent.Metal:Play()
	elseif script.Parent.Materials.Value == "DiamondPlate" then
		script.Parent.Diamond:Play()
	elseif script.Parent.Materials.Value == "Concrete" then
		script.Parent.Concrete:Play()
	elseif script.Parent.Materials.Value == "Slate" then
		script.Parent.Concrete:Play()
	elseif script.Parent.Materials.Value == "Foil" then
		script.Parent.Foil:Play()
	elseif script.Parent.Materials.Value == "Brick" then
		script.Parent.Brick:Play()
	elseif script.Parent.Materials.Value == "Granite" then
		script.Parent.Granite:Play()
	elseif script.Parent.Materials.Value == "Marble" then
		script.Parent.Marble:Play()
	elseif script.Parent.Materials.Value == "Sand" then
		script.Parent.Sand:Play()
elseif script.Parent.Materials.Value == "Pebble" then
		script.Parent.Pebble:Play()	
elseif script.Parent.Materials.Value == "Pebble" then
	script.Parent.Pebble:Play()   end
	end 

function isRunning()
    if running and Humanoid.Parent.HumanoidRootPart.Velocity.magnitude > 1 then
        return true
    end
end


Humanoid.Jumping:connect(function()
    running = false;
end)


function doWhileRunning()
    Connection:disconnect();
    running = true;
    while (isRunning()) do
        WhileRunning()
        wait(0.351)
    end
    running = false;
    Connection = Humanoid.Running:connect(doWhileRunning);
end

Connection = Humanoid.Running:connect(doWhileRunning)

The thing that “running” returned when I died ;

22:46:47.810 - Stack Begin
22:46:47.810 - Script 'Workspace.TheFirm_F.HumanoidRootPart.Running', Line 25 - function WhileRunning
22:46:47.811 - Script 'Workspace.TheFirm_F.HumanoidRootPart.Running', Line 64 - function doWhileRunning
22:46:47.812 - Stack End

Thanks for helping ! :smile:

You define ‘Humanoid’ in the beginning. Whenever the character dies in game, that instance is lost. To solve that you could simply update the value whenever a new character is added.

Also, instead of using such a long chain of if-else statements, why not use something like this?

function WhileRunning() 
	script.Parent[script.Parent.Materials.Value]:Play()
end
1 Like

Thanks for your answer ! I don’t get you on the first part of your answer. I’m not a scripter at all, some friends are better at that but I want to understand a bit about that to prevent from this kind of issue later !

For the second part, thank you. I didn’t knew that we could do like that, but it is very logic. Thanks !

I should note that you shouldn’t use free model scripts. It’s already a mess, and it may be worthwhile to make your own instead.

What i mean by the first part is using a CharacterAdded event to redefine the humanoid variable.
Also,
Example:

local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local humanoid = plr.Character.Humanoid

plr.CharacterAdded:Connect(function(Char)
    humanoid = Char.Humanoid
end)