What did I do wrong in my cash button script

	local x = math.random(1,2)
	local debounce = false
	if debounce == false then
		z.leaderstats.Cash.Value = z.leaderstats.Cash.Value + x
		debounce = true
		wait(1)
		debounce = false
	end
end)```
is my current script, I get an indexing nil error.

If that’s the entire code snippet and it’s occurring on those lines one of the following is nil:(z, leaderstats, Cash) this may be due to another mistake. Without knowing where the script is placed the only thing I am able to suggest is to only add cash, if it isn’t nil:

--rest of your code
local x = math.random(1,2)
local debounce = false 
if not debounce then
	local leaderstats = z:FindFirstChild("leaderstats")
	if not leaderstats then return end 
	local Cash = leaderstats:FindFirstChild("Cash")
	if not Cash then return end 
	Cash.Value += x
	debounce = true
	wait(1)
	debounce = false
end
end)

PS: If you never get cash when you click it. Make sure the value Cash inside leaderstats exists in the first place.

Would you be able to provide the full script?