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)
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
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