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

How do I change the text of a TextLabel with a script in the workspace?


local label = game.StarterGui.TimeLeft.Frame.TimeLeftLabel
local ready = game.StarterGui.TimeLeft.Frame.Ready.ReadyToVisit
local currentmin = currentdaymin + currenthourmin + currentminutemin
local beforemin = beforedaymin + beforehourmin + beforeminutemin
local timeoffline =  math.abs(currentmin - beforemin)
print(currentmin)
print(beforemin)
print(timeoffline)

while true do
if ready.Value == false then

repeat
print("repeat")
label.Text = timeoffline
wait(5)
until ready.Value == true

end
wait(5)	
end





end

This is in a script in the workspace. The repeat thing keeps on going, but the text isn't changed, even if I make the text say "test".

Help? How can I change the local text using a script?

Update/Breakthrough I looked at the startergui and playergui, and the startergui is updated to 0 so when I reset, it works. I haven't tested it yet, but will it make it 0 for all the players, or just for the local?

3 comments

0

Uhh.. Is "StarterGui" a child of "game"? I don't think so ._.

1

...Yes it is, StarterGui is in fact a child (and service) of game.

0

Yes it is TomsGames, I figured out instead of going to startergui, ill go to the playergui instead

3 answers

✓ Accepted answer
local label = game.StarterGui.TimeLeft.Frame.TimeLeftLabel
local ready = game.StarterGui.TimeLeft.Frame.Ready.ReadyToVisit
local currentmin = currentdaymin + currenthourmin + currentminutemin
local beforemin = beforedaymin + beforehourmin + beforeminutemin
local timeoffline =  math.abs(currentmin - beforemin)
print(currentmin)
print(beforemin)
print(timeoffline)
Game.Players.PlayerAdded:connect(function(player)
    coroutine.resume(coroutine.create(function()
        local PlayerGui = player:WaitForChild('PlayerGui')
        local ready, label =  PlayerGui.TimeLeft.Frame.Ready.ReadyToVisit,      PlayerGui.TimeLeft.Frame.TimeLeftLabel
        while true do
            if not ready.Value then
                repeat
                    label.Text = timeoffline
                    wait(5)
                until ready.Value
            end
            wait(5) 
        end
    end
end

You seem to want something like this, please inform me if I am mistaken.

This script would be best as a local script in StarterGui. Other than that and the comments below, I don't have much to add.The loop at the end might need some work, but I don't know what you need to do with it.

local label = game.StarterGui.TimeLeft.Frame.TimeLeftLabel --change "game.StarterGui" to "LocalPlayer.PlayerGui".
local ready = game.StarterGui.TimeLeft.Frame.Ready.ReadyToVisit -- same here

local currentmin = currentdaymin + currenthourmin + currentminutemin
local beforemin = beforedaymin + beforehourmin + beforeminutemin
local timeoffline =  math.abs(currentmin - beforemin)

print(currentmin)
print(beforemin)
print(timeoffline)

while true do
	if ready.Value == false then
		repeat
			print("repeat")
			label.Text = timeoffline
			wait(5)
		until ready.Value == true
	end
	wait(5) 
end

To change the GUI for every player at once, use a for loop.

However, this is not the optimal method, due to your use of the 'ready' value. I suggest either making this a LocalScript inside StarterGui that every player gets, or changing where the ready Value is located, so that there is only one of it.

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