How to change the value of a leaderstat variable

I have a variable (Cash) inside of this leaderstat function and I want to increase the value of the leaderstat everytime a player touches a part.

CashLeaderstat - Roblox Studio 10_26_2021 7_48_27 PM (2)

local Players = game:GetService("Players")
local CashGiver = workspace.Teleport1

local Debounce = false

CashGiver.Touched:Connect(function(hit)
	if Debounce then return end
	if hit and hit.Parent:FindFirstChild("Humanoid") then
		local Client = Players:GetPlayerFromCharacter(hit.Parent)
		
		if Client then
			Debounce = true
			task.delay(1, function()
				Debounce = false
			end)
			Client.leaderstats.Cash.Value += 1
		end
	end
end)
4 Likes

You absolutely need a debounce for this because Touched is awfully unreliable when it comes to consistency.

thanks, I had tried something similar to this before but it didnt work but this one worked perfectly fine.