Strange delay when tweening IntValue

I have a custom player list where it lists players and their cash. Using TweenService and IntValues, the cash TextLabel seen in the player list will smoothly ease into the number it should be, giving it a slot-machine-esque animation.

However, when the player’s money value changes, the cash TextLabel takes a long while for it to change over to the final number. Example video below.


Notice in the output that I have also decided to keep record of the TextLabel’s text itself, and it is indeed supposed to be the correct number at that time, but it for some reason does not show that in client until a few seconds later, way later when the tween is supposed to end.

This is the main LocalScript in the PlayerList ScreenGui itself.

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)

local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(.3)

local GUI = script.Parent
local list = GUI.List

local function PlayerAdded(player: Player)
	if list:FindFirstChild(player.UserId) then return end
	
	local plate = script.PlayerTemplate:Clone()
	plate.Name = player.UserId
	plate.NameLabel.Text = player.DisplayName
	plate.Parent = list

	local moneyLabel = plate.MoneyLabel
	
	
	-- The player's actual money value is stored in a folder inside the Player object named "Temp"
	local moneyValue: IntValue = player:WaitForChild("Temp"):WaitForChild("Money")
	
	-- creates the tween
	local tweenValue = Instance.new("IntValue", script)
	
	local moneyConnection
	moneyConnection = moneyValue:GetPropertyChangedSignal("Value"):Connect(function()
		TweenService:Create(
			tweenValue,
			tweenInfo,
			{
				Value = moneyValue.Value
			}
		):Play()
	end)
	
	-- sets the cash's TextLabel
	local tweenConnection
	tweenConnection = tweenValue:GetPropertyChangedSignal("Value"):Connect(function()
		moneyLabel.Text = tweenValue.Value
		
		print(string.format(`Tween Value: %s | Label Text: %s`, tweenValue.Value, moneyLabel.Text))
	end)
	
	
	player.Destroying:Connect(function()
		plate:Destroy()
		moneyConnection:Disconnect()
		tweenConnection:Disconnect()
		tweenValue:Destroy()
	end)
end

Players.PlayerAdded:Connect(PlayerAdded)

for _, player in Players:GetPlayers() do
	PlayerAdded(player)
end

This could just be an honest bug with the engine, I’m not sure how else to exactly fix this considering the output detects that the TextLabel is correctly displaying what it should be despite not being true in game. More insight is appreciated.

1 Like

this is something ive found out myself not too long ago its a little odd behavior stemming from easing direction

to get rid of the delay make your tween info use inout direction

local tweenInfo = TweenInfo.new(.3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

above should fix it, did type it out of memory so it may have an error

Strangely this doesn’t seem to work for me.

Unrelated to the post, but I notice you’re using backticks for strings. Amusingly, the entire reason backticks can be used for strings is because in Luau you can use string interpolation with them. Take the example above, it can instead be written as:

print(`Tween Value: {tweenValue.Value} | Label Text: {moneyLabel.Text}`)
1 Like

Looking at the video closer, it seems the value ticks over when your cursor goes over the text label. Can you confirm this?

1 Like

As far as I can tell this is beyond your control. Your code seems fine and the print statement’s output would suggest all is working. It’s either an engine bug or some other code snippet is modifying the text label immediately after the content is set to its final value.
I would recommend verifying this using task.wait() and a second print statement after the first.

1 Like

This does appear to be the case. This is strange because there are absolutely no events connected related to any mouse hovers in any instance of the player list ScreenGui. The TextLabel updates when I either hover over the TextLabel, or a certain amount of time has passed.

The only way the TextLabel can be updated in this case is when “tweenValue” is updated. There is no other case where the TextLabel is tampered with.

This is entirely speculation on my part. It may be that Roblox “defers” updates to a text label when changes occur in rapid succession. I would suggest trying a different approach to the same problem or circumvent the problem entirely with a different effect.

1 Like

perhaps using a number value object instead of a int value may fix the issue (the tweening object), you will need to incorporate rounding the value though since it will include decimals

other than that the code looks fine, maybe try different easing style.

1 Like

How to tween an integer value? - Help and Feedback / Scripting Support - Developer Forum | Roblox

Will this help?

Found a solution!

I simply added a task.wait() before updating the TextLabel and it now updates to the final number in time.

	-- sets the cash's TextLabel
	local tweenConnection
	tweenConnection = tweenValue:GetPropertyChangedSignal("Value"):Connect(function()
		task.wait()
		moneyLabel.Text = tweenValue.Value
	end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.