Because youre not updating the display variable(it only gets assigned once, at the start of the script). put it inside the while true loop so it gets updated. Ill edit this answer later if it isn't sufficient since I'm using a phone
It should also be in local script because playergui is invisible to server
Updated Code
local text = script.Parent
while wait() do
local display = game.Workspace.Generator.ClickButton.ClickDetector.PowerCore.Energy.Value
dis = tostring(display)
text.Text = "Total energy: " .. dis
end
I recreated the situation in studio, and it works fine. Make sure to put local script INSIDE the textlabel
The reason for this is when you declare the value at the start of the script
Original Code
local text = script.Parent
local display = game.Workspace.Generator.ClickButton.ClickDetector.PowerCore.Energy.Value
while wait() do
dis = tostring(display)
text.Text = "Total energy: " .. dis
end
Suppose the starting value of energy is 3. Since the variable display only gets assigned the value once (When the game starts) The variable will keep the value 3 until it is updated again. If you put it inside the while loop like in the first given code, the variable gets updated constantly with the Energy Value
7 comments
If the energy is 0, it should stay 0?
the energy goes up by 0.2 every 2 seconds, but the GUI doesn't update the value
Example: i have a function to print the amount of energy every second, and it counts up, while the GUI stays at 0. sorry i phrased the question wrong lol
Ah, its fine. Anyways is the code in a localscript or script? Make sure its enabled too.
the code is in a regular script. should it be in a local script?
Dude, why are you using tostring on a value that is already a string?
Also, it's going to have to be in a localscript if you're trying to access the player's playergui.