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

How do I output the value of a variable in textlabel?

Asked by 7 years ago

Google translator, sorry

local value = workspace.PlayerValues.BrownMaterial.Value

while true do 
    game.StarterGui.HudGui.MainFrame.PlayerStats.BrownMaterial.Text = value
    wait()
end

I showed the value of a variable, everything is OK, but if it changes, the text of the textlabel remains the same

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago

The StarterGui holds GUIs to be later copied and given to players when they spawn.

There is no point in your scripts changing its contents.


You should use a LocalScript and modify the current player's GUI:

-- I assume that this script is a child of "HudGui":

local value = workspace.PlayerValues.BrownMaterial.Value

while true do
    script.Parent.MainFrame.PlayerStats.BrownMaterial.Text = value
    wait()
end

However, you never "refresh" value -- the script saves the value that it was when it sets value = .......

You need to grab value again in each iteration of the while loop if you want to show the "live" value:


while true do local value = workspace.PlayerValues.BrownMaterial.Value script.Parent.MainFrame.PlayerStats.BrownMaterial.Text = value wait() end
Ad

Answer this question