Get Cash by kill with Pistol

So I have the Problem that when I do kill someone with sword it gives cash but when i do it with pistol it does not!

Code:

game.Players.PlayerAdded:Connect(function(plr)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = plr
	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = stats
	local deaths = Instance.new("IntValue")
	deaths.Name = "Deaths"
	deaths.Parent = stats
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Parent = stats
	plr.CharacterAdded:connect(function(char)
		local humanoid
		repeat
			humanoid = char:FindFirstChild("Humanoid")
			wait()
		until humanoid
		humanoid.Died:connect(function() 
			deaths.Value = deaths.Value + 1 
			local tag = humanoid:FindFirstChild("creator") 
			if tag then  
				local killer = tag.Value  
				if killer then   
					killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
					killer.leaderstats.Cash.Value = killer.leaderstats.Cash.Value + 50
				end   
			end 
		end)     
	end)
end)
3 Likes

Well… what is your code? I can’t help if i dont know what your code is like

2 Likes

Maybe you didnt set the creator when the pistol hits someone

3 Likes

I did and it works with sword so that can’t be the Problem!

1 Like

Well, you aren’t giving too many details… but the pistol probably just doesn’t add the “tag” that your code is using.

2 Likes

Then how do i check it right I do not know?

1 Like

what did you put as the code for the pistol when it sets the tag?

2 Likes

I did put nothing in the weapon :frowning:

1 Like

How do i check it with a pistol?

1 Like

when pistol hits someone, get the player from character it hit and set the tag

2 Likes

Well, you will have to edit the pistol’s code to set the tag.
Find in the pistol code where it does damage, and add something like

if --[[player hit]]:FindFirstChild("creator") then
	--[[player hit]]:FindFirstChild("creator").Value = --[[player using gun here]]
end

Because of how vague this is, it would be hard to help you past this point. Good luck!!

2 Likes

Doesn’t work if there was only a script for it :frowning:

You need to make sure that gun has something like this:

local Debris = game:GetService("Debris")

function TagHumanoid(humanoid, player)
	local Creator_Tag = Instance.new("ObjectValue")
	Creator_Tag.Name = "creator"
	Creator_Tag.Value = player
	Debris:AddItem(Creator_Tag, 2)
	Creator_Tag.Parent = humanoid
end

And eventually call it when gun hits.
Something like this:

TagHumanoid(Target.Humanoid,Player) -- Player is the killer

This would create a tag named ‘creator’ under the target’s humanoid. And when they died by you, you would be able to award the killer.

1 Like

Is your gun compatible with the ‘creator’ tag system?