If is only checked when script first runs

Hi, ive made a script for buying an item purchase with ingame money, however, when checking if the player has enough, it only checks it the first time around and doesnt check it again so if the player starts with not enough and gains enough they cant buy it and if they have enough then buy it and then not have enough they can still buy it

local script


local b = require(game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Modules"):WaitForChild("case"))


local debounce = false
script.Parent.Activated:Connect(function()
	game.SoundService["DDLC - Select Sound Effect"]:Play()
if debounce == false then
debounce = true
if game.Players.LocalPlayer.leaderstats.Cash.Value >= 0.38 then -- problematic line
local a = require(game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Modules"):WaitForChild("case")):create("Basic")
task.wait()
		game.SoundService["Ding Ding!"]:Play()
	task.wait(1)
	local item = b.newResult.Name
		local numb
		if item == "RGB Headphones" then
			numb = 8
		elseif	item == "ChillCap" then
			numb = 9
			elseif item == "Interesting Coin" then
	numb = 10
		elseif item == "Colorful Banana" then
	numb = 11
		elseif item == "Party Fedora" then
	numb = 12
		elseif item == "Rich Shades" then
	numb = 13
		elseif item == "Shark Necklace" then
			numb = 14

			
		end
		local price = 0.38
		game.ReplicatedStorage.Cases.BuyCase:FireServer(numb, price)
	task.wait(3)
	debounce = false
end
end
end)

I think you should do it inside a server script instead of a local script

the entire thing breaks as a serverscript and it is secure as a local script since the item giving is handled by the server

then you’re still able to change the amount of money you have no? unless that’s also handled by the server

anyway,

i’m not sure what happens inside of game.ReplicatedStorage.Cases.BuyCase:FireServer(numb, price)

but if it doesn’t substract (is it substract or subtract?!?!?!) the value then the player will always be able to buy it, same with having too little money

i can’t really see any other issues other than this, is your value actually being changed?

the issue with it being moved to the server is that everything is set up to work for the client which will take hours to fix, it changes the values but doesnt acknowledge if the player has too little money or enough so if you have enough the first time you roll it, you always can roll it and it subtracts money into the negetives which i dont want, and if you start with less than you need to buy it, and then gain enough to do so, it still acts like you dont have enough

There is no issue in the script really, the problem might be that it is a LocalScript. I recommend using server script for such things, to prevent exploiters and any unwanted bugs.

Maybe the problem is with the ModuleScripts, but i don’t think so. Make sure to check your checking the correct cash value u have right now, maybe u forgot that u put the cash somewhere else and not leaderstats.

well i don’t really have a proper solution for you other than doing it server side