Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a GUI TextLabel display a numbervalue?

Asked by 3 years ago

I'm currently working on a sports game and I have a scoreboard. I'm stumped on how to make the scoreboard display the actual score. I have a number value with the score that works when scoring. So that'd have the score in it, but no matter what I try I can't seem to get it to display. The scoreboard TextLabel is in startergui and the numbervalue is in replicated storage if that helps any. RedScore is the number value.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local displayValues = ReplicatedStorage:WaitForChild("DisplayValues")
local status = displayValues:WaitForChild("RedScore")

local textLabel = script.Parent

local function updateText()
    textLabel.Text = status.Value
end

status.Changed:Connect(updateText)
updateText()

1 answer

Log in to vote
0
Answered by
Jac_00b 157
3 years ago

The problem is that you are trying to set a string value (the textlabel's text) to a number value. To fix this, simply put a tostring() around status.Value. So your new 8th line would be

textLabel.Text = tostring(status.Value)

tostring() simply converts anything that can be a string into a string. But since you're using a number value, you shouldn't have to worry.

0
So I changed the line 8, but It's still not displaying. Does it have anything to do with the text label being the script's parent? NortonHDD 21 — 3y
0
Ah, the problem was line 3, I had changed it to game.replicatedstorage.RedScore and it worked perfectly. Thanks! NortonHDD 21 — 3y
Ad

Answer this question