Help saving past properties

I am trying to make a level up system. You can click on the button to make the stat go up, if you have enough exp, then you can confirm. In this system, you can go from 15 to 19 and then confirm, rather than confirming instantly. The problem, however, is that i can’t get it to save the last level. For example, you can go from 15 to 20, then go back to 18 before confirming, but currently, it only saves the previous level, and once you go back, it doesnt have anything to go back to and breaks.

							--DEFINING NEW STATS BEFORE LEVELING
							local soon = Instance.new("IntValue", v)
							soon.Name = "soon"
							soon.Value = v1.Value
							soon:SetAttribute("stat", v1.Value + 1)
							soon:SetAttribute("level", level.Value + 1)
							soon:SetAttribute("needed", math.round((level.value)^3 * 0.02 + (level.value)^2 * 3.06 + (level.value) * 105.6 - 895))
							soon:SetAttribute("souls", souls.Value - needed)
							--DEFINING STATS FROM PAST LEVEL
							local last = Instance.new("IntValue", v)
							last.Name = "last"
							last.Value = v1.Value
							last:SetAttribute("stat", v1.Value)
							last:SetAttribute("level", level.Value)
							last:SetAttribute("needed", needed)
							last:SetAttribute("souls", souls.Value)

				--SAVING LAST ATTRIBUTES (getting last level's properties before they change)
				v:FindFirstChild("last"):SetAttribute("stat", v:FindFirstChild("soon"):GetAttribute("stat")) 
				--RAISING STAT LABEL (changing the properties)
						v:FindFirstChild("soon"):SetAttribute("stat",  v:FindFirstChild("soon"):GetAttribute("stat") + 1) 
						v:FindFirstChild("new").Text = "> "..v:FindFirstChild("soon"):GetAttribute("stat")

Basically, soon is the next level’s values, which will be used in the confirmation, and last would be the previous level, in case you want to go back before confirming. How would i go about making more than one “Last” without doing it manually? I could just make Last2, Last3 and so on, but i’d rather learn a better way.

Put your stats from the past before the new stat.

--DEFINING STATS FROM PAST LEVEL
							local last = Instance.new("IntValue", v)
							last.Name = "last"
							last.Value = v1.Value
							last:SetAttribute("stat", v1.Value)
							last:SetAttribute("level", level.Value)
							last:SetAttribute("needed", needed)
							last:SetAttribute("souls", souls.Value)
                                           --DEFINING NEW STATS BEFORE LEVELING
							local soon = Instance.new("IntValue", v)
							soon.Name = "soon"
							soon.Value = v1.Value
							soon:SetAttribute("stat", v1.Value + 1)
							soon:SetAttribute("level", level.Value + 1)
							soon:SetAttribute("needed", math.round((level.value)^3 * 0.02 + (level.value)^2 * 3.06 + (level.value) * 105.6 - 895))
							soon:SetAttribute("souls", souls.Value - needed)
1 Like
  v:FindFirstChild("needed").Text = v:FindFirstChild("soon"):GetAttribute("needed").." souls"
  v:FindFirstChild("level").Text = v:FindFirstChild("soon"):GetAttribute("level")
  v:FindFirstChild("souls").Text = v:FindFirstChild("soon"):GetAttribute("souls").." souls"
  
--GOING BACK BEFORE CONFIRMATION
v:FindFirstChild("soon"):SetAttribute("stat", v:FindFirstChild("last"):GetAttribute("stat"))
  v:FindFirstChild("new").Text = "> "..v:FindFirstChild("soon"):GetAttribute("stat")
  v:FindFirstChild("needed").Text = v:FindFirstChild("soon"):GetAttribute("needed").." souls"
  v:FindFirstChild("level").Text = v:FindFirstChild("soon"):GetAttribute("level")
  v:FindFirstChild("souls").Text = v:FindFirstChild("soon"):GetAttribute("souls").." souls"

I am not too familiar with roblox coding, but I am going to try to help you.
If you want the system to save the last level, you’d have to make an object for it.
You could do this by making an object:
local lastLevel = Instance.new(“IntValue”, v)
lastLevel.Name = “LastLevel”
lastLevel.Value = v1.Value
lastLevel:SetAttribute(“stat”, v1.Value)
lastLevel:SetAttribute(“level”, level.Value)
lastLevel:SetAttribute(“needed”, needed)
lastLevel:SetAttribute(“souls”, souls.Value)

Then, you could set your the attributes of the object to be equal to the same attributes of the object you created earlier.
I hope this helped!