Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a textlabel say the value of a numbervalue?

I'm making a story game and I'm trying to make a countdown that shows how much time is left before the car leaves so I make a number value and it doesn't work.

2 answers

This is code assuming that you want to change textlabel that is in Gui:

local Player = game.Players.LocalPlayer
local NumberValue = game.Workspace.NumberValue -- Path to NumberValue
local Countdown = Player:WaitForChild("CountDown").TextLabel -- Path to Textlabel

Countdown.Text = tostring(NumberValue.Value) -- Set it for the first time

NumberValue:GetPropertySignalChanged("Value"):Connect(function() -- Awoid while wait() do loop in this case as this is better on performance
	Countdown.Text = tostring(NumberValue.Value)	
end)

2 comments

0

I think you might need to use a remoteEvent/Function for grabbing the NumberValue.Value, I've tried accessing value instances from localscripts before but it always returns 0.

0

You don't if it's not stored in place client can't access

make the number value become the script's parent

change the number value parent to a text label

you can do this (script):

local numvalue = script.Parent
local text = script.Parent.Parent
local countdown = 20

while wait() do

numvalue.Value = countdown

repeat
	text.Text = numvalue.Value
	numValue.Value = numValue.Value - 1
wait until countdown == 0
end

sorry for the late response :P please mkar this as the correct answer is that helped you, ill check this out later, bye 8)

2 comments

0

This is wrong at many levels, There is no reason to have countdown variable and numvalue(countdown should be handled by the server) also in case you want that, this countdown would be done within sec because there isn't wait() and you should decrease the value before applying it to text as it will be late 1 sec in your case.

0

And you can't change textlabel with script(only if it's in surfacegui or bilboardgui inside workspace)

This discussion is preserved as it was. New answers, comments, and votes are closed.