How to make a Kill to earn money system?

try

local Players = game:GetService("Players");

script.Parent.Humanoid.Died:Connect(function()
	local playerWhoKilled = script.Parent.Humanoid:GetAttribute("LastHitBy");
	print(playerWhoKilled)
	Players[playerWhoKilled].data.Cash.Value += math.random(70,120)
end)

nil. do i show you the code i used?

no im just trying to make a new version wait

i have creator tag which has the name of last hit

ok um can u send ur current code rn

local Players = game:GetService("Players");

script.Parent.Humanoid.Died:Connect(function()
	local playerWhoKilled = script.Parent.Humanoid:WaitForChild("creator").value
	print(playerWhoKilled)
	Players[playerWhoKilled].data.Cash.Value += math.random(70,120)
end)

ok then try this:

local Players = game:GetService("Players");

script.Parent.Humanoid.Died:Connect(function()
	local playerWhoKilled = script.Parent.Humanoid:WaitForChild("creator").value
	print(playerWhoKilled)
	Players:FindFirstChild(playerWhoKilled).data.Cash.Value += math.random(70,120)
end)

attemp to index nil with data is the only error now

ill come back tommorow and try using getplayerfromcharacter

wait then one last thing for the Players variable remove the “;” at the end

it does no change i tried… i will try to find the solution on yt

sure i will give you solution if you help

maybe this might help

ill try this tommorow. if it works i give you a solution

1 Like
local PlrHitTable = {
	
}

local Plr1 = nil --example
local Plr2 = nil -- example
local Plr3 = nil -- exmple

local function AGotHitByB(A, B)
	PlrHitTable[A] = B
end

local function CharSetup(Plr)
	PlrHitTable[Plr] = nil
	
	Plr.Character.Humanoid.Died:Once(function()
		if PlrHitTable[Plr] ~= nil then
			local MyKiller = PlrHitTable[Plr]
			
			--Reward The Killer
		end
	end)
end

game:GetService("Players").PlayerAdded:Connect(function(Plr)
	repeat task.wait() until Plr.Character
	CharSetup(Plr)
	Plr.CharacterAdded:Connect(function()
		CharSetup(Plr)
	end)
end)

--Example A got hit by B
AGotHitByB(Plr1, Plr2)

i hope u get the idea

thats not the problem. reward the killer is the problem

i was here days ago and i returned back seeing 96 comments. Wud???

can i have a short explanation of the problem? i will try to help you

he dont know how to increment the value of his own intvalue?

i want to give the player money when killed an npc. i made a script so now i can see who killed the npc but i cant give the player money. the script i used is:

local Players = game:GetService("Players");

script.Parent.Humanoid.Died:Connect(function()
	local playerWhoKilled = script.Parent.Humanoid:WaitForChild("creator").value
	print(playerWhoKilled)
	Players:FindFirstChild(playerWhoKilled).data.Cash.Value += math.random(70,120)
end)

what error does it give? what type of value are you using? and is a localscript?