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

Why does the change in a Value doesn't copy the change into a GUI text?

Asked by
mine248 40
8 years ago

I made a script to make a GUI make the time change by one second. Time changes from a Script, not a LocalScript. I tested it, but the change takes effect on the "Timer" Value. It won't take effect on the GUI. Any solutions?

Snippet:

local Infomation = script.Parent:WaitForChild("Infomation")
local replicated = game:GetService("ReplicatedStorage")

Infomation.Text = replicated.Timer.Value
0
Is this the full code? I don't think this is enough for SH to help you with. Azmidium 388 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Here's what you need to do:

local Infomation = script.Parent:WaitForChild("Infomation")
local Timer = game.ReplicatedStorage.Timer

Timer.Changed:connect(function()
    Infomation.Text = Timer.Value
end

Here's a quick rundown of what changed.

First, I changed this top bit

local Infomation = script.Parent:WaitForChild("Infomation")
local replicated = game:GetService("ReplicatedStorage")

To this

local Infomation = script.Parent:WaitForChild("Infomation")
local Timer = game.ReplicatedStorage.Timer

You don't really need a variable that represents ReplicatedStorage, just a variable for the Timer itself.

Next, I changed this:

Infomation.Text = Timer.Value

to this:

Timer.Changed:connect(function()
    Infomation.Text = Timer.Value
end

The issue before is that you only set the TextLabel's Text to the Timer's Value once. Therefore, it won't update. When you set something to the value of the Timer, it doesn't link them together in some sort of an automatic connection. Instead, what happens, is the Information's Text gets changed to the current Value of Timer.

What the new solution does is update Information's Text every time Timer's Changed event fires (which would be every time a property of Timer changes).

I hope this helped you. Good luck!

0
I think that you need a Variable for replicated service. mine248 40 — 8y
0
Nope. Programmix 285 — 8y
Ad

Answer this question