You followed the syntax correctly, however you still have many issues here:
Issue 1: Wrong ScreenGui
Anything placed under StarterGui
gets cloned to Player.PlayerGui
whenever a player joins. game.StarterGui.ScreenGui
is not referencing the actual ScreenGui being shown on a given playerâs screen, itâs referencing the original source of the ScreenGui. You should type game.Players.LocalPlayer.PlayerGui.ScreenGui
instead of game.StarterGui.ScreenGui
.
Issue 2A: Setting The Property
I assume your goal is to change the Text property of TextLabel so that it displays different text. When you type timer =
, you are not changing the property of the TextLabel
instance, you are changing the variable named timer
.
Example:
local variable = workspace.Part
variable = workspace.Model
print(variable)
Output:
> Model
Issue 2B: Setting The Property
When you set the variable timer
as game.StarterGui.ScreenGui.Frame.TextLabel.Text
, youâre setting the variable timer
to the property Text
of the TextLabel
instance. If you want to modify one of an instanceâs properties, you have to start with the instance; you canât start with the property, otherwise youâll simply be reassigning a variable.
Incorrect example:
local part = workspace.Part.Color
part = Color3.new(1, 1, 1)
print(part)
print(part.Color)
Output:
> 1, 1, 1
> Error: Color is not a valid member of Color3
Correct example:
local part = workspace.Part
part.Color = Color3.new(1, 1, 1)
print(part)
print(part.Color)
Output:
> Part
> 1, 1, 1
If you fixed all of that, the text should change to display â12:01â. Problem is, it stays like that forever.
Issue 3: Looping
Imagine the loop as if you were the machine that was reading and interpreting the code, line-by-line, and try translating it from ROBLOX Lua back into regular English.
Step 1: while true do
= âIf true
is not true
, continue to next step, otherwise skip to next end
.â
Step 2: timer.Text = "12:01"
= âChange the Text
of TextLabel
to â12:01â.â
Step 3: wait(1)
= âWait 1 second.â
Step 4: timer.Text = "12:012
= âChange the Text
of TextLabel
to â12:02â.â
Step 5: end
= âSince this is a while
loop, go back to step 1 and see if we still need to do it again.â
So, if we were to go through this twiceâŚ
Action 1: True is true. Continuing to next step.
Action 2: Changing the text to â12:01â.
Action 3: Waiting 1 second.
Action 4: Changing the text to â12:02â.
Action 5: Going back to step 1.
Action 6: True is still true. Repeating.
Action 7: Changing the text to â12:01â.
Action 8: Waiting 1 second.
Action 9: Changing the text to â12:02â.
Action 10: Going back to step 1.
The first and most obvious observation you likely made was that the text is being set to â12:01â, then being set to â12:02â, then being set back to â12:01â and repeating forever. We donât want it to be switching back and forth; we want it to be counting up. To do that, youâll have to add a variable as a number, add to that number each loop, then concatenate that number to a string when setting the text.
local secondsPassed = 0
while true do
secondsPassed = secondsPassed+1
timer = "12:"..secondsPassed
wait(1)
end
The second issue with the loop (as @ThatTimothy explained) was the lack of a second wait
, but that isnât applicable here anymore since weâve changed the code.
Despite all of this writing, I still havenât explained every issue that will come up here. After 9 seconds, your timer will start displaying â12:010â, and after 60 seconds itâll display â12:060â. It would be too time-consuming for me to guide you through this entire thing in one reply, so youâll have to figure out some of it on your own.
If youâre still confused about any of this, check out these sources and see if theyâre any help:
Variables Variables
Loops Loops
Strings Strings