Script doesn't detect humanoid health property change

So I have this damagable model with a humanoid inside of it, and it works fine until it is killed a second time. After the humanoid is killed, it is destroyed, and cloned from replicatedstorage after the cooldown. It successfully is cloned, and takes damage correctly, however the GetPropertyChangedSignal function is never triggered. I’ve looked at similar issues with respawning npc humanoids, but they dont seem to correlate with my issue.

The damage is coming from server scripts, and since this is also a server script it should be able to detect the damage, but it doesn’t

(line 19 is where it is spawned)

local Humanoid = game.ReplicatedStorage.Humanoid
Humanoid.MaxHealth = 100

local human = script.Parent:FindFirstChild("Humanoid") or Humanoid:Clone()
human.Parent = atm
human:GetPropertyChangedSignal("Health"):Connect(function()
	if COOLDOWN == false and atm:WaitForChild("Humanoid").Health <= 0 then
		robbed = true
		game.ReplicatedStorage.health:FireAllClients(robbed == true)
		COOLDOWN = true
		sound:Play()
	close.Transparency = 1
	close.CanCollide = false
	open.Transparency = 0
		open.CanCollide = true
		script.Parent:FindFirstChildOfClass("Humanoid"):Destroy()
		wait(cooldown_time)
		COOLDOWN = false
	local human =  Humanoid:Clone() -- where the humanoid is spawned again
		human.Parent = atm
		close.Transparency = 0
		close.CanCollide = true
		open.Transparency = 1
		open.CanCollide = false
	end
end)
1 Like

Instead of GetPropertyChangedSignal, try using HealthChange.

Instance.new("Humanoid").HealthChanged:Connect(function(Health)
	
end)

I changed it to .HealthChanged, but wouldn’t Instance.New make a new humanoid each time it’s health changes ?

Humanoid.HealthChanged:Connect(function(Health)

I’m not sure why they added Instance.new().

https://developer.roblox.com/en-us/api-reference/event/Humanoid/HealthChanged

What if you change it from an anonymous function to a named one? Then you can connect it again, after you replace the humanoid.

function HealthChange ()
  if COOLDOWN == false and atm:WaitForChild("Humanoid").Health <= 0 then
 -- etc
		local human =  Humanoid:Clone() -- where the humanoid is spawned again
		human.Parent = atm
		human:GetPropertyChangedSignal("Health"):Connect(HealthChange) -- added
-- etc
end

-- connect function
local human = script.Parent:FindFirstChild("Humanoid") or Humanoid:Clone()
human.Parent = atm
human:GetPropertyChangedSignal("Health"):Connect(HealthChange)

1 Like

It works! thank you so much, this has been bugging me for the past few days :sweat_smile: