Why does this not work lol

game.ReplicatedStorage.talkBegin.OnClientEvent:Connect(function(criminal, deathMethod, name)
local npc = game.Workspace:FindFirstChild(name)
	print("NPC'S NAME IS "..npc.Name)
	local property = npc.Humanoid.Health
	while wait() do
		if property <= 0 then
			game.Players.LocalPlayer.Character.Humanoid.AutoRotate = true
			game.Players.LocalPlayer.Character.HumanoidRootPart.Anchored = false
			game.ReplicatedStorage.changeTalkValue:FireServer(false)
			script.Parent:Destroy()
		end
	end

end)

the print statement runs
this is in a local script, and i checked yes the health is changed on the client the humanoid is dead lol

but it doesnt happen
it doesnt destroy() anything it doesnt run the code in the “if property <= 0 then” statement

Can you try to elaborate what’s actually happening? Are you getting any errors? Where’s the LocalScript parented to?

no errors and the print statement runs
after that it doesnt run any of the code despite the dude’s health clearly on the client and server being 0

its a child of a frame inside a screengui in playergui

You’re setting property equal to the current health of the humanoid. The value does not update when the humanoid’s health changes. Use the HealthChanged event of the humanoid, or check for the current value of the humanoid’s health in your loop.

1 Like

how do i check the current value

thats what i had thought i was doing lol

and for health changed is it literally just

npc.Humanoid.HealthChanged:Connect(function())
if npc.Humanoid.Health == 0 then
--run code
end
end)

In your loop, just get rid of the variable “property” entirely and check the humanoid’s health in the if statement like this:

game.ReplicatedStorage.talkBegin.OnClientEvent:Connect(function(criminal, deathMethod, name)
local npc = game.Workspace:FindFirstChild(name)
	print("NPC'S NAME IS "..npc.Name)
	while wait() do
		if npc.Humanoid.Health <= 0 then
			game.Players.LocalPlayer.Character.Humanoid.AutoRotate = true
			game.Players.LocalPlayer.Character.HumanoidRootPart.Anchored = false
			game.ReplicatedStorage.changeTalkValue:FireServer(false)
			script.Parent:Destroy()
		end
	end

end)

The way you have it setup, if you use that variable it will only store that npc’s health once and never update

im just now trying it
i hate this
i was like
“maybe i should get rid of the variable”

“…nah why would that be a problem”

variables… you just gotta love em

on the one hand yippee thanks you both that saved me from further hours of struggle for no good reason

on the other hand
DARN IT
to think it was so easy…! this entire time…!?