In the following script, whenever I call the function "updateClass" only the textLabel.Text value gets changed, therefore, I have to call the function twice (as shown in line 15) in order for the function to change both textLabel.Text and textLabel.BackgroundColor3. This feels counterintuitive and I was wondering if I'm doing something wrong or if this is as good as it can get. If additional clarification is needed, please don't hesitate to tell me. All help is appreciated!
local Players = game:GetService("Players") local player = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):wait() local class = game.ReplicatedStorage:WaitForChild(player.Name):WaitForChild("Class") local classColor = game.ReplicatedStorage:WaitForChild(player.Name):WaitForChild("CColor") local textLabel = script.Parent local function updateClass() textLabel.Text = class.Value textLabel.BackgroundColor3 = classColor.Value end updateClass() class.Changed:Connect(updateClass) classColor.Changed:Connect(updateClass)
You're listening for two separate values, and therefore you can wait for the other property to change if you'd like instead of creating another listener connected to the function:
local function updateClass() classColor.Changed:Wait() -- Yields until classColor changes -- Something else here end
If one value changes, the function fires and will boldly assume that both values have changed. According to your information, the color value doesn't change when the Text changes.