So I've been trying to get my XP Script to function so if the player's bullet hits the NPC, you gain a certain number of XP, and once you kill that NPC, you gain a certain number as well, yet all my efforts on trying to get this solved haven't worked. Yet, there's no errors in the script, or when ran. So, if anyone knows how to fix this script or what to change, I'd love to the help! Thanks!
function onHealthChanged() local zHuman = script.Parent:findFirstChild( "Humanoid" ) if zHuman ~= nil then local tag = zHuman:findFirstChild( "creator" ) if tag ~= nil then if tag.Value ~= nil then local stats = tag.Value:findFirstChild("XP") if stats ~= nil then if tag.Value.Character ~= nil then stats.XP.Value = stats.XP.Value + 20 end end end end end end function onDeath() local zHuman = script.Parent:findFirstChild( "Humanoid" ) if zHuman ~= nil then local tag = zHuman:findFirstChild( "creator" ) if tag ~= nil then if tag.Value ~= nil then local stats = tag.Value:findFirstChild("XP") if stats ~= nil then if tag.Value.Character ~= nil then stats.XP.Value = stats.XP.Value + 200 end end end end end end script.Parent.Humanoid.Died:connect(onDeath) script.Parent.Humanoid.HealthChanged:connect(onHealthChanged)
Okay well when you're doing the if else statement on line 3 you are not calling the health you are just calling the property. If it were nill then it would not exist. And it always exist. To fix it just do "Zhuman.health"