My NPC Isn't Giving Me Cash On Kill

I have been making a game with my friend and I came across a problem. I scripted a cash per kill for an npc based on a tutorial
This is 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.Cells.Value = leaderstats.Cells.Value + 50
			end
		end
	end
end

It would not give me cash on kill.

Here is a video on my problem:

I’ve tried looking at multiple tutorials, but each end up with the same result, failure.

What am I doing wrong?

4 Likes

There was a post about this recently. Do you have a script which gives them the creator tag? make sure it affects npcs too if you do

To clarify: the creator tag IS NOT given by the corescripts. You have to add it manually.

2 Likes

I haven’t but how might I give them the creator tag?

1 Like
3 Likes

But where would I put it in my script?

1 Like

When any damage is dealt (or when the other humanoid dies)

1 Like

I’ve tried it, but it doesn’t seem to work.

Show us the code on how you are adding the tag to the NPC on weapon hit

Okay, so here’s the photo, maybe you can help me now?

Screenshot 2021-07-08 093143

Maybe this will work, haven’t tested it so let me know if it works.
local Humanoid = script.Parent.Humanoid

function TagHumanoid(Hum, Attacker)
	if not Hum:FindFirstChild("Creator_Tag") then
		local CreatorTag = Instance.new("ObjectValue")
		CreatorTag.Name = "Creator_Tag"
		CreatorTag.Value = Attacker
		CreatorTag.Parent = Hum
        game.Debris:AddItem(CreatorTag, 2)
	elseif Hum:FindFirstChild("Creator_Tag") then
		local CreatorTag = Hum:FindFirstChild("Creator_Tag")
		CreatorTag.Value = Attacker
	end
end

function Died()
	local Tag = Humanoid:FindFirstChild("Creator_Tag")
	if Tag ~= nil and Tag.Value ~= nil then
		local PlayerOfAttacker = game.Players:GetPlayerFromCharacter(Tag)
		if PlayerOfAttacker:IsA("Player") then
			local Leaderstats = PlayerOfAttacker:FindFirstChild("leaderstats")
			if Leaderstats then
				Leaderstats.Cells.Value = Leaderstats.Cells.Value + 50
			end
		end
	end
end
2 Likes

Hmmm… its still at 0 cells…

Here’s the script that the sword uses, maybe it’ll help?

local sword = script.Parent
local canDMG = false


local function onTouch(otherPart)
	
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	
	if not humanoid then
		return
	end

	if humanoid.Parent ~= sword.Parent and canDMG then
		
		
		humanoid:TakeDamage(10)
		
	else
		
		return
	end
	
	canDMG = false
end

local function slash()
	local str = Instance.new("StringValue")
	str.Name = "toolanim"
	str.Value = "Slash"
	str.Parent = sword
	canDMG = true
end

sword.Activated:Connect(slash)
sword.Handle.Touched:Connect(onTouch)
1 Like

you didnt add a debris variable yet! add:
Debris = game:GetService(“Debris”)

It still doesn’t seem to work…

Screenshot 2021-07-08 224738
Screenshot 2021-07-08 224727

1 Like

I put the Debris variable already…
I don’t see any errors so i don’t know the issue.

did you add a creator tag? i see that you didnt put it.

and some how you didnt add a player yet!

I’m using a tool from a tutorial and I’m not good a scripting, how might I add the creator tag to the sword and put a player in?

i sure it have a getplayerfromcharacter
here is the link!
Players:GetPlayerFromCharacter (roblox.com)

So, I put the GetPlayerFromCharacter thing somewhere in my sword script? Where though?