I need help with Kill for Cash when killing an enemy

I am having the same problem like this guy:
(Kill for cash script not working)

When I kill the zombie with a sword, it gives money, when I kill zombie with a pistol that I created, it don’t give the money to the player.

robloxapp-20220303-0013432.wmv (1.1 MB)

I have the script of the gun right here:

The script of Kill for Cash:

local Humanoid = script.Parent.Zombie
function PwntX_X() 
	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.Money.Value = Leaderstats.Money.Value + 1 --Change Money to the stat that is increased. 
				wait(0.1) 
				script:remove() 
			end 
		end 
	end 
end 
Humanoid.Died:connect(PwntX_X) 
2 Likes

Before I suggest anything can you confirm if there were any errors related to this script?

1 Like

I don’t know if this will work or not.

local Humanoid = script.Parent.Zombie

function Zombie()
	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 + 150 
				wait(0.5)
				script:remove()
			end
		end
	end
end

Humanoid.Died:connect(Zombie)
1 Like

Try doing this script (made by Gamer M8):

game.Players.PlayersAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local cash = Instance.new("NumberValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats

player.CharacterAdded:Connect(function(Character)
Character.Humanoid.Died:Connect(function(Died)
local creator = Character.Humanoid:FindFirstChild("creator")
local leaderstats = creator.Value.FindFirstChild("leaderstats")
if creator ~= nil and creator.Value ~= nil then
leaderstats.Cash.Value = leaderstats.Cash.Value + 10
     end
  end)
 end)
end)

You can change the number +10 to how much cash you want the player to get when they kill someone.

1 Like

Oops, sorry if I didn’t specified it right, I meant when the player kills an enemy like a zombie.

1 Like

I don’t see any message errors, basically when I kill with sword, gives money to the player, and when I kill with the pistol I created, it don’t give money to the player.

Kill for Cash with ranged weapons is different from Kill for Cash with melee weapons.

1 Like
  1. Have you already setup the “leaderstats” serverside for each player when they join?
  2. Does your weapon damage script create the “creator” tag on the hit NPC?
  3. Do you have an event on the NPC that looks for the “creator” tag when it dies to attribute the cash/XP to the relevant player?

How I do it with ranged weapon?

1 Like
  1. The leaderstas is serverside.
  2. I don’t create a weapon to have creator tag.
  3. It is on the script.

You can use attributes, they’re perfect for something like that

1 Like