I was watching other videos but it did not work my currency is named gold pls help! I put this script in the npc.
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)
Basically, the creator
tag under the humanoid when they die is a life saver.
It gives you who killed the humanoid.
On to the topic. It doesn't actually works since it's not replicated to the server, if its in a local script.
Also WHY did you do this: leaderstats.Cash
it should be leaderstats.Gold
!
Example code, script runs when a npc dies:
local npc = script.Parent -- script in npc model local remote = game.ReplicatedStorage.GiveCash npc.Humanoid.Died:Once(function() local tag = npc.Humanoid:WaitForChild("creator") tag.leaderstats.Gold.Value += 10 end)