Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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

0
This script is if you are killing others players. I mean like for an NPC in workspace if the npc is dead Mohawkid14 28 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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
0
on line 17 you can keep it script:remove() or replace it with 'break' decla123 45 — 7y

Answer this question