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 detect if a npc humainoid is at 0?

I am making a game where you kill NPC. but i can not figure out how to write this.(The script is to give gold to me when i kill an npc) Located in startergui:

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!

1 answer

Its usually better to put the localscript into the Tool of the sword.

Try using a sword and use this script. (Put it into the tool)

Use this link to learn how to make a sword if you dont know. (Also needed for the "Hitmark" part in the script: How to make a sword

local hitmark = script.Parent.hitname --Let this be the part that damages the player 
--(May need to watch the tutorial provided above) 

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")

hitmark.Touch:connect(function(npc)
	if npc.Parent.Name == "Viking" and npc.Parent.Humanoid.Health == 0 then -- Checks if the NPC killed is named Viking and checks if dead
		leaderstats.Currency.Value = leaderstats.Currency.Value + 50 -- Adds currency
	end
end)

Im not that professional at scripting but this is what I know. Use the Output of any errors. If the output does not help however, it may give you an idea on what to do.

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