Can't Detect NPC Death

Hi there!

What my script is supposed to do is change an IntValue when it is killed.
This is a regular script in my NPC model, and my NPC uses a Humanoid. All of the paths are correct as well.
The script doesn’t seem to run, heres the code:

local character = script.Parent

local value = workspace.NPCsKilled

character:WaitForChild("Humanoid").Died:Connect(function()

value.Value = value.Value + 1

print(character.Name .. " has died!")

end)

Help would be appreciated.

1 Like
while wait() do
local character = script.Parent
if character.Humanoid.Health <= 0 then
local value = workspace.NPCsKilled
value = value + 1
print(character.Name .. " has died!")
    end
end
1 Like

Thanks Ill try it out real quick!

No problem, I hope it will help you.

Wait, what is the value variable? An Int Value?

If it is a value, it shouldn’t work.

I changed it so its like this:

value.Value = value.Value + 1

but its still not working

I’ll fix it, is it? So I know.

Of course, it confuses roblox studio.

What should I do instead of that?

local character = script.Parent
local Kills = workspace.NPCsKilled
if character.Humanoid.Health <= 0 then
Kills.Value = Kills.Value + 1
print(character.Name .. " has died!")
    end
end

Is it a local script? If so you need another code.

No, its a regular script. Its still not working for me its shows this error:

Workspace.Zombie.DetectDeath:7: Expected <eof>, got 'end'

yep i missed something lol, try this

local character = script.Parent
local Kills = workspace.NPCsKilled
if character.Humanoid.Health <= 0 then
Kills.Value = Kills.Value + 1
print(character.Name .. " has died!")
    end

It should work 1000000%, my opinion.

It’s still not working for some reason

You should probably break the loop after the value has increased or else it will keep increasing the value.

Also Instance’s aren’t a number, so you’ll need to get the value property instead.

hmm, i didn’t think about that

Ok. I added the .value after the instance

Wait you didnt add a loop to this script thats why lol