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)