Issue with humanoid.Died

I"m making an ability script and whenever the players dies during it the wall doesn’t delete so I made a function to detect if the player dies. But when the player dies it doesn’t print nor does it destroy the wall clone

local RS = game:GetService("ReplicatedStorage")
local HammersModule = require(RS.HammersModule)
local TweenService = game:GetService("TweenService")

local Tool = script.Parent.Parent.Parent
local Utility = Tool:FindFirstChild("Utility")

Utility.Ability.OnServerEvent:Connect(function(Player)
	
	local Char = Player.Character
	local humanoid = Char:FindFirstChild("Humanoid")
	local HRP = Char:WaitForChild("HumanoidRootPart")
	

	local Wall = RS.Abilities.BrickHammer.BrickWall:Clone()
	Wall.CFrame = HRP.CFrame * CFrame.new(0, -10, -10)
	Wall.Parent = workspace
	
	local Sound = Instance.new("Sound")
	Sound.SoundId = HammersModule["Normal Hammers"][Tool.Name]["Ability SoundID"]
	Sound.Volume = HammersModule["Normal Hammers"][Tool.Name]["Ability Volume"]
	Sound.TimePosition = 0.87
	Sound.RollOffMaxDistance = 50
	Sound.RollOffMinDistance = 4
	Sound.Parent = Wall
	
	local goal1 = {}
	goal1.CFrame = HRP.CFrame * CFrame.new(0, 0, -10)
	local tweenInfo1 = TweenInfo.new(1.3,Enum.EasingStyle.Bounce)
	local tween1 = TweenService:Create(Wall, tweenInfo1, goal1)
	
	local goal2 = {}
	goal2.CFrame = HRP.CFrame * CFrame.new(0, -10, -10)
	local tweenInfo2 = TweenInfo.new(1.3,Enum.EasingStyle.Quint)
	local tween2 = TweenService:Create(Wall, tweenInfo2, goal2)
	
	Wall.ParticleEmitter.Enabled = true
	tween1:Play()
	Sound:Play()
	wait(0.3)
	Wall.ParticleEmitter.Enabled = false
	
	wait(5)
	
	Wall.ParticleEmitter.Enabled = true
	tween2:Play()
	Sound:Play()
	wait(0.3)
	Wall.ParticleEmitter.Enabled = false
	wait(1)
	
	Wall:Destroy()
	Sound:Destroy()
	
	humanoid.Died:Connect(function()
		print("Died")
		Wall:Destroy()
		Sound:Destroy()
	end)
	
end)

I find that humanoid is usually lower case so ‘humanoid’ for some reason. Maybe try using this in place?

local humanoid = Char:WaitForChild("humanoid")

You have a ton of yields (waits, in this case) before the Humanoid.Died listener gets connected. This means that you could die before the Died event even gets a chance to be connected.

Also, you’re connecting a new Humanoid.Died event every single time the remote gets fired — you should either connect this somewhere else in the script (when they spawn, maybe) or use a table with connections inside and check if the player already has a Died connection so you don’t create multiple ones on accident

1 Like