Function Runs multiple times?

For some reason the function below runs multiple times after the character dies?




Character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	if Humanoid.Health == 0 then
		Character.Head.face:Destroy()
		local Blood = ReplicatedStorage.DeathFX.Blood:Clone()
		local Skin = ReplicatedStorage.DeathFX.Skin:Clone()
		Blood.Parent = Character.Torso
		Skin.Parent = Character.Torso
		Skin.Color = ColorSequence.new(Character.Torso.Color)
		Blood:Emit(50)
		Skin:Emit(10)
		for i,limb in pairs(Character:GetChildren()) do
			if limb:IsA("Accessory") then
				limb:Destroy()
			end
			if limb:IsA("Part") and limb.Name ~= "HumanoidRootPart" then
				limb.Transparency = 1
				local duplicatelimb = limb:Clone()
				duplicatelimb.Transparency = 0
				duplicatelimb.CanCollide = true
				duplicatelimb.Anchored = false
				duplicatelimb.Color = colors[math.random(1,#colors)]
				duplicatelimb.Parent = game.Workspace.FX
				local velocity = Instance.new("BodyVelocity")
				velocity.Velocity = Vector3.new(math.random(5,10),math.random(40,50),math.random(5,10))
				velocity.P = math.random(20,30)
				velocity.Parent = duplicatelimb
				Debris:AddItem(velocity,0.1)
			end
		end
	end
end)
1 Like
local last = tick()

Character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
     local elasped = tick()-last 
     if Humanoid.Health == 0 and elapsed >= 1 then
                last = tick()
		Character.Head.face:Destroy()
		local Blood = ReplicatedStorage.DeathFX.Blood:Clone()
		local Skin = ReplicatedStorage.DeathFX.Skin:Clone()
		Blood.Parent = Character.Torso
		Skin.Parent = Character.Torso
		Skin.Color = ColorSequence.new(Character.Torso.Color)
		Blood:Emit(50)
		Skin:Emit(10)
		for i,limb in pairs(Character:GetChildren()) do
			if limb:IsA("Accessory") then
				limb:Destroy()
			end
			if limb:IsA("Part") and limb.Name ~= "HumanoidRootPart" then
				limb.Transparency = 1
				local duplicatelimb = limb:Clone()
				duplicatelimb.Transparency = 0
				duplicatelimb.CanCollide = true
				duplicatelimb.Anchored = false
				duplicatelimb.Color = colors[math.random(1,#colors)]
				duplicatelimb.Parent = game.Workspace.FX
				local velocity = Instance.new("BodyVelocity")
				velocity.Velocity = Vector3.new(math.random(5,10),math.random(40,50),math.random(5,10))
				velocity.P = math.random(20,30)
				velocity.Parent = duplicatelimb
				Debris:AddItem(velocity,0.1)
			end
		end
	end
end)

I added a one second debounce.

How does that even help? It changes nothing lmao, i need to find why the PropertyChanged triggers 3-4 times

Fixed it myself, forget about it

PropertyChanged is not the best option for checking when a humanoid dies, you should use Humanoid.Died.

I modified your code and added a debounce so after it calls once it will mark the timestamp and when it calls again it will check if the elasped time is greater than 1.

What was the issue/solution? (

i just made a status folder into the character and then checked for the dead status

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.