Need help with my NPC Reward Script

Hello, so I’m trying to make a NPC so when you kill him, he gives you an amount of XP, but for some reason my code doesn’t seem to work.

Here is my code:

local humanoid = script.Parent.Humanoid


humanoid.Died:Connect(function()
	
	local tag = humanoid:FindFirstChild("creator")

	if tag ~= nil then
		if tag.Value ~= nil then

			local leaderstats = tag.Value:FindFirstChild("leaderstats")

			if leaderstats ~= nil then
				leaderstats.Yen.Value = leaderstats.Yen.Value + 100
				wait(0.1)
				script:Remove()

			end
		end
	end
end)

The Script is place into the NPC:

If you have any ideas of why it doesn’t work, please tell me!

Can U Put The Script In The Post, and put where the script is

What would the value of “creator” be?

I am also confused about what creator and tag mean…

However, it looks like you are searching for leaderstats inside of tag.Value which to me doesn’t seem very intuitive. If I’m guessing right then leaderstats is a folder inside of the player. Unless of course tag holds the instance of the player.

Something else worth mentioning is that this script doesn’t work if it’s local for it cannot interact with those values.

Try telling us more about what tag and creator are please

It’s the name of the last player that hit the NPC I think.
I’m not really sure because I watched a tutorial.

I edited the post everyone, so you can copy the code to edit it and see where it is located in the Explorer.

Nevermind I figured it out! The problem was that the ‘creator’ value was nil. So I had to do a little bit of code in my weapon so it creates a ‘creator’ value inside the Humanoid of the NPC when I hit them with my ability. Thanks again for helping, everyone :smiley: