Shop Button not giving unless on death

I am making a button to buy stuff, Coins, in a shop with burned calories and when someone buys it it doesnt fully give it to them unless they leave or reset

my computer is too bad for a video but you regain your calories and dont gain the coins when you buy unless you die or leave

here is the script below

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local calories = player:WaitForChild("leaderstats").CaloriesBurned.Value
local Coins = player:WaitForChild("Hidden").Coins.Value

local function onClick()
	if Coins == 1 then	 
			if calories >= 100 then
				calories = calories - 100 
				Coins = Coins + 1
				game.ReplicatedStorage.Values:FireServer(player.leaderstats.CaloriesBurned, calories)
				game.ReplicatedStorage.Values:FireServer(player.Hidden.Coins, Coins)
				player.Character.Humanoid.Health = -1	
			else
				warn("Missing " .. (100 - calories) .. " calories")
			end
		end
	-- more of them repeated
	if Coins == 40 then 
			print("Max Upgrade")
	end
end
script.Parent.MouseButton1Click:Connect(onClick)

is there a reason why you need to set the player’s health to negatives?

just to kill them 0 would dothe same but -1 is kinda funny and its to update it (the calories and coins) for the player so they cant regain the calories spent

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local calories = player:WaitForChild("leaderstats").CaloriesBurned
local Coins = player:WaitForChild("Hidden").Coins

local function onClick()
	if Coins.Value == 1 then	 
		if calories.Value >= 100 then
		    calories.Value -= 100 
			Coins.Value += 1
			game.ReplicatedStorage.Values:FireServer(player.leaderstats.CaloriesBurned, calories.Value)
			game.ReplicatedStorage.Values:FireServer(player.Hidden.Coins, Coins.Value)
			player.Character.Humanoid.Health = 0
		else
			warn(string.format("Missing %i calories!", 100 - calories.Value))
		end
	end
	-- more of them repeated
	if Coins.Value == 40 then 
		print("Max Upgrade")
	end
end

script.Parent.MouseButton1Click:Connect(onClick)

Your script set a variable to the leaderstats values, but never updated them. If you started with 109 calories, the variable would be forever 109. If this is in StarterCharacterScripts, that explains your issue. To fix this, remove .Value from your variable assignments and instead place them where you set the values.

this is attached to the button that you press to buy not in starter character scripts, would this still work?

That’s because the ScreenGUI refreshes, just use the code I wrote.

this is giving me the same errors as before, it just takes it for a second and noting else happens, it doesnt take it forever and it doesnt give me the coins for when i gain caloriesburned, it just puts it back