Well, I have already done something that I want to represent a TextLabel text (what I did try to increase or decrease the number), and well I want to do that if it is 10 of number (or another number) and it goes down to 5, in the text it looks like it goes down to 5. I guess what I want to do can be done with TweenService, or no idea
1 Like
I don’t really understand what you are trying to make, but you can just use tween service for text labels like any part.
example:
wait(5)
local label = script.Parent -- The reference to the label
local ts = game:GetService("TweenService")
local tweenI = TweenInfo.new(0.5) -- you can define different values, the first value is the duration, but look up the documentation for more
local goals = {Transparency = 0.75, Position = UDim2.fromScale(0.5, 0.5), Size = UDim2.fromScale(0.75, 0.6)} -- these are the values that you will end up with when the tween is done, and what is tweening.
local tween = ts:Create(label, tweenI, goals) -- creating a tween, which can be played, cancelled, has events etc.
tween:Play() -- playing the tween
tween.Completed:Connect(function()
print("The tween is done")
end)
Hope it helped!
1 Like
Ah sorry, I don’t think I made myself understood. I will give an example: if I have a 10 value of NumberValue and it goes down to 5, I want a text from textLabel to represent the number but with the difference that it will do it like this: 10, 9, 8, 7 and so on until reaching 5
ah didn’t realize what you were asking for my mistake, but I think I got it now.
local label = script.Parent
local value = script.Parent.Parent.Value
-- the value currently visible
local prevV = value.Value
-- what value the last event started with, used to detect if a new event happened
local currentEventV
value.Changed:Connect(function()
-- the starting value of this event call
local currentV = prevV
-- setting the last event to this one
currentEventV = currentV
-- checking if the number is lower or higher than the current
local dir = math.clamp(value.Value - prevV, -1, 1)
for i=currentV, value.Value, dir do
if currentV ~= currentEventV then
-- A new change has happened
return
end
label.Text = i
prevV = i
wait(0.25)
end
end)
2 Likes