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.
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:
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.
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.
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.
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.