Issue with tools and leaderstats

I am trying to make a tool that when clicked, will add one cash to the players Cash value on the leaderboard, the code will not execute properly and the cash value remains as 0.

local tool = script.Parent
function CashGiverTool(player)
	local PlayerCash = player.leaderstats.Cash
	PlayerCash.Value = PlayerCash.Value + 1
end

tool.Activated:Connect(CashGiverTool)

where is the player variable defined?

1 Like

the player variable needs to be defined differently. Activated does not pass the player variable.

local tool = script.Parent
function CashGiverTool()
	local player = game.Players:GetPlayerFromCharacter(tool.Parent)
	local PlayerCash = player.leaderstats.Cash
	PlayerCash.Value = PlayerCash.Value + 1
end

tool.Activated:Connect(CashGiverTool)
1 Like