Hi there, I’m Crystallityy and I started learning to script on Roblox and I’m trying to make a counter on GUI.
local counter = game.StarterGui.Counter.TextLabel
for i = 1,20,1 do
wait(1)
print(i)
counter.Text = i
end
Does someone know how to make this work?
Thank you.
1 Like
ShutzCh
(Shutz)
February 7, 2021, 10:50am
#2
Does the output say you are attempting to change the text to a number value instead of string?
If so, do the following:
local text = tostring(i)
this will convert the number value to a string value.
The extra 1 isn’t needed in my experience, try removing the 1 as demonstrated above.
Another issue is you are doing it in a server script and changing the startergui.
Create a LocalScript parented to the GUI and define the gui by doing
local counter = game.Players.LocalPlayer.PlayerGui:WaitForChild(“Counter”).TextLabel
then add the rest of the code.
2 Likes
ShutzCh:
local text = tostring(i)
There’s no error in my output, I’m only getting prints from my counter.
ShutzCh
(Shutz)
February 7, 2021, 10:55am
#6
@IEnforce_Lawz just pointed out the Starter Gui problem.
local player = game.Players.LocalPlayer
local text = player.PlayerGui (your Gui and text here)
Starter Gui is the Gui players gets upon spawning, for already existing UIs you need to get the already cloned one as described above.
Thanks, you helped me to solve it. It is working now.
1 Like