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

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

Asked by 10 years ago

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?

0
Uhh.. Is "StarterGui" a child of "game"? I don't think so ._. TomsGames 225 — 10y
1
...Yes it is, StarterGui is in fact a child (and service) of game. User#2 0 — 10y
0
Yes it is TomsGames, I figured out instead of going to startergui, ill go to the playergui instead tkddude2 75 — 10y

3 answers

Log in to vote
2
Answered by 10 years ago
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.

Ad
Log in to vote
3
Answered by 10 years ago

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
Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

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.

Answer this question