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
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.
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