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.