Kill for cash script not working

I used a lot of YouTube tutorials but none worked and An issue might just be that I also have another leaderstats but it seems fine But that’s not the issue. so the issue is that when I kill a player I don’t get a reward


	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"

	local cash = Instance.new("IntValue",leaderstats)
	cash.Name = "Cash"
	cash.Value = 0

	local kills = Instance.new("IntValue",leaderstats)
	kills.Name = "Kills"
	kills.Value = 0


	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function(killed)

			local CreatorTag = character.Humanoid:FindFirstChild("creator")

			if CreatorTag and CreatorTag.Value then

				local stats = CreatorTag.Value:WaitForChild("leaderstats")

				stats["Cash"].Value = stats["Cash"].Value + 20
				stats["Kills"].Value = stats["Kills"].Value + 1   
			end
		end)
	end)
end)
1 Like

The problem is most likely that the tool you use to kill the player doesn’t create the “creator” tag or does not set its value.

2 Likes

This kill for cash script also breaks my sword shop…

Make sure the swords you use to kill players make the creator tag and also define their value.

I’m sorry I’m new to scripting How would I do that?

Just check the sword’s script and search for something like "creator".

ye there is no creator to what i see

Can I see the damaging part of the sword script? It would help if I could add a part to it to make sure that it creates the creator tag and defines it.

Sure, Thanks!


Handle.Touched:Connect(function(Hit)
	
	if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent ~= Tool.Parent then
		
		if Debounce == true and PlayersHit[Hit.Parent] == nil then
			
			Hit.Parent:FindFirstChild("Humanoid"):TakeDamage(30)
			
			PlayersHit[Hit.Parent] = true
			wait(1)
			PlayersHit[Hit.Parent] = nil
		end
	end
end)

Alright, try replacing that part with this:

Handle.Touched:Connect(function(Hit)
	
	if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent ~= Tool.Parent then
		
		if Debounce == true and PlayersHit[Hit.Parent] == nil then
			
			local hithum = Hit.Parent:FindFirstChild("Humanoid")

			if hithum.Health > 0 then
				hithum:TakeDamage(30)
				if hithum.Health <= 0 then
					local creatortag = hithum:FindFirstChild("creator") or Instance.new("ObjectValue")
					creatortag.Name = "creator"
					creatortag.Value = game.Players:GetPlayerFromCharacter(Tool.Parent)
					creatortag.Parent = hithum
				end
			end
			
			PlayersHit[Hit.Parent] = true
			wait(1)
			PlayersHit[Hit.Parent] = nil
		end
	end
end)
2 Likes