So I’m trying to create a Level System, and now I’m turning it into UI, So when doing the Status for EXP compared to Required EXP, But I’m not sure how to do this, I have used a for loop, but this makes the code ugly and doesn’t work when its constantly changing.
Current Code:
EXP.Changed:Connect(function()
local Item = LFrame.Frame.S
local Status = LFrame.Frame.Status
local NewSize = UDim2.fromScale(EXP.Value/REXP.Value, 1)
local NewText = tostring(math.floor(EXP.Value))
TweenService:Create(Item, TweenInfo.new(.5), {Size = NewSize}):Play()
task.spawn(function()
--[[ Stupid
for i = 1,EXP.Value do task.wait()
Status.Text = i
end
]]
end)
end)
EXP.Changed:Connect(function()
local Item = LFrame.Frame.S
local Status = LFrame.Frame.Status
local NewSize = UDim2.fromScale(EXP.Value/REXP.Value, 1)
local NewText = tostring(math.floor(EXP.Value))
local Tween = TweenService:Create(Item, TweenInfo.new(.5), {Size = NewSize})
Tween:Play()
Tween.Changed:Connect(function()
Status.Text = EXP.Value
end)
end)
It would change the text value while the tween is running. You could also add a Status.Text = NewText at the end if the value does not finish with the correct number.
You can still try dividing the value your changing it by into smaller numbers and adding them (Like I’ve said), or you can multiply decimals if you feel fancy
You Could use multiplication of decimals for a smoothed effect but that’s just a little bit harder to do unless your ending number is 0
(ex: Value = Value*0.98)
Edit: If the number is close to 1, like really close, itay cause the number to take a while to reach 0
Edit2: You don’t need to do this if you just want a tween effect
The code I made replicates the current transition from the tween so it could also be made with a second one if you need but I think that would just be a waste of time as it should follow the bar’s animation transition.