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)

7 comments
Is this script in the player's character?
Script is in the NPC's character.
A lot of thing are deprecated in this script. E.g 'findFirstChild" should be 'FindFirstChild'. and at the end, 'connect' should be 'Connect'
here's a fact: leaderstats are not located in the character with the Humanoid, that's why it isn't working
Okay, so where should I place the script? In ServerScriptService, Workspace, or?
inside of the player
but in order to make that work you have to edit the script quite a bit: for example, find when the bullet hits the NPC from a server script, use a remote event to fire that event to the client and then change the stats via the client