What is the way to determine the remainder when a number is changed

Hello,

I’m currently working on a project that users can click a button to add one or subtract one to a skill for their player. I have a pretty simple question, but can’t quite seem to wrap my head around the best way of doing this!

Here is my code, the only problem I’m getting is when a player subtracts from a stat, I get an error.

local pGui = plr:WaitForChild("PlayerGui"):WaitForChild("Gui")
	local max
	
	pGui['abilitiesFrame']['points']['current'].Changed:Connect(function()
		if pGui['abilitiesFrame']['points']['current'].Value > 0 then
			max = pGui['abilitiesFrame']['points']['max'].Value - pGui['abilitiesFrame']['points']['current'].Value
		else
			max = 0
		end
		print(max)
	end)

I’m assuming what I’m trying to accomplish is self-explanatory, just doesn’t help I’m not the best at explaining things! If you can help, please let me know what I can do to fix this! Thank you for reading, have a great rest of your day/evening!

hmm yes, do this:

local pGui = plr:WaitForChild("PlayerGui"):WaitForChild("Gui")	
local points = pGui['abilitiesFrame']['points']
points['current'].Changed:Connect(function()
	max = points['current'].Value > 0 and points['max'].Value - points ['current'].Value or 0
    print(max)
end)