Get award on kill problem

Hello guys so for some reason i made a award script and my script is not giving money with my own made sword but with the roblox sword it give the player the money so if you could help here the code:

local Humanoid = script.Parent.Humanoid
function dead()
	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.Cash.Value = leaderstats.Cash.Value +10
				wait(0.1)
				script:Remove()
			end
		end
	end
end
Humanoid.Died:Connect(dead)

thank you for reading this!

Try this assuming that leaderstats is in the player

local Humanoid = script.Parent.Humanoid
function dead()
	local tag = Humanoid:FindFirstChild('creator')
	if tag and tag.Value then
			local leaderstats = game.Players[tag.Value]:FindFirstChild('leaderstats')
			if leaderstats ~= nil then
				leaderstats.Cash.Value = leaderstats.Cash.Value +10
				wait(0.1)
				script:Destroy()
		end
	end
end
Humanoid.Died:Connect(dead)

nope it’s not working and it not working with the roblox sword too but thx for trying to help me!

I think it’s because you removed the script before calling the function try this one

local Humanoid = script.Parent.Humanoid
function dead()
    local tag = Humanoid:FindFirstChild('creator')
    if tag ~= nil then
            local leaderstats = tag.Value:FindFirstChild('leaderstats')
            if leaderstats ~= nil then
                leaderstats.Cash.Value = leaderstats.Cash.Value +10       
        end
    end
end
Humanoid.Died:Connect(dead)
         wait(0.1)
        script:Destroy()

np same thing as the other person!

leaderstats.Cash.Value += 10

Sorry about formatting, I am on mobile. (Shouldn’t change the script, but it is good practice).

i don’t think that’s would work because there no script to start this function!

You need to put the script inside the NPC becuase if you have

local Humanoid = script.Parent.Humanoid

yea i put it inside it’s weird!

  1. Any errors?
  2. Does your sword has a tag system?
local Humanoid = script.Parent.Humanoid
local plr = game.Players.LocalPlayer
if not Humanoid or Humanoid.Health == 0 then
  plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 222
end
--maybe this
local Humanoid = script.Parent.Humanoid
function Death() 
  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.Cash.Value = Leaderstats.Cash.Value + 1 
end 
end 
end 
end 
Humanoid.Died:Connect(Death)

As @anirudh851 mentioned before. Does your sword have a tag system?

The roblox default sword has a tag system where when a player is hit → it creates a objectValue called creator, sets its value to the player who hit the target and parents it to the targets humanoid.

i think it’s the problem because idk how to do that’s