Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i know if a NPC health humanoid is at 0 to add money to leaderboard?

I have a script located in the startergui and it if you kill the npc you earn gold. I have a saving currency. Heres script:

local player = script.Parent.Parent
local leaderboard = player:WaitForChild("leaderstats")
local currency1 = leaderboard:WaitForChild("Gold")

function onDied()
    print("Dead")
    currency1.Value = currency1.Value + 100
end

script.Parent.Parent.Workspace.TutPrac.Viking.Humanoid.Died:connect(onDied)

thanks!

2 answers

I guess do it like:

local player = game.Players.LocalPlayer
local human = player.Character.FindFirstChild("Humanoid")
local helt = human.Health

if helt == 0 then 
	print 'He ded.'
end

^^ Should do the trick, if not then im sorry.

-TheArcticTerminal

1 comment

0

This script is if you are killing others players. I mean like for an NPC in workspace if the npc is dead


local player = script.Parent.Parent

local leaderboard = player:WaitForChild("leaderstats")

local currency1 = leaderboard:WaitForChild("Gold")

 

while wait(0.1) do

if workspace.TutPrac.Viking.Humanoid.Health <= 0 then

    print("Dead")

    currency1.Value = currency1.Value + 100

    script:remove()

end

end

1 comment

0

on line 17 you can keep it script:remove() or replace it with 'break'

This discussion is preserved as it was. New answers, comments, and votes are closed.