I’m trying to make a screen GUI that counts down from 100, but if I press play or play here it doesn’t work, it freezes at 100 or 99. But if I press run it does work. The script’s parent is workspace and I tried switching from LocalScript to just Script but it still doesn’t work and I don’t know why. here’s the script:
local TextOnScreen = game.StarterGui.ScreenGuiUntilSmushed.SmushText.Text
local goal = 100
local addnumm = 0
while true do
wait(1)
addnumm = addnumm + 1
TextOnScreen = TextOnScreen -1
if addnumm == 100 then
TextOnScreen = 100
end
end
Also if I reset my character it goes down a bit but then it freezes again
local player = game.Players.LocalPlayer
local TextOnScreen = player.PlayerGui.ScreenGuiUntilSmushed.SmushText
local goal = 100
local addnumm = 0
while true do
task.wait(1)
addnumm += 1
TextOnScreen.Text -= 1
if addnumm == goal then
TextOnScreen.Text = 100
break
end
end
You assigned the text to a variable. Also, you are editing StarterGui, so you should use PlayerGui.
local TextOnScreen = game.StarterGui.ScreenGuiUntilSmushed.SmushText
local goal = 100
local addnumm = 0
while true do
task.wait(1)
addnumm += 1
TextOnScreen.Text -= 1
if addnumm == goal then
TextOnScreen.Text = 100
break
end
end
If you are editing a GUI of a Player. You should mention PlayerGui, also if the script is a LocalScript. You should put this script in StarterGui
Also for a shorter way of using a timer, you could use for loops
Other thing is your script is using the string of the Text for a Number, instead make the string the number ex of your script with the stuff I said
local player = game.Players.LocalPlayer
local TextOnScreen = player.PlayerGui:WaitForChild("ScreenGuiUntilSmushed").SmushText
local goal = 100
local addnumm = 0
for T = 0, goal do
task.wait(1)
addnumm += 1
TextOnScreen.Text = T
if addnumm == goal then
TextOnScreen.Text = "100"
end
end
If you want the opposite, from 100 to 0, just do this
local player = game.Players.LocalPlayer
local TextOnScreen = player.PlayerGui:WaitForChild("ScreenGuiUntilSmushed").SmushText
local goal = 100
local addnumm = 0
for T = goal, 0, -1 do
task.wait(1)
addnumm += 1
TextOnScreen.Text = T
if addnumm == goal then
TextOnScreen.Text = "0"
end
end
No, this would go into StarterGui. Also, @XtraSpeedyYT’s solution may be much better, but his also has some problems, so here’s a fixed version of that:
local player = game.Players.LocalPlayer
local TextOnScreen = player.PlayerGui.ScreenGuiUntilSmushed.SmushText
local goal = 100
local addnumm = 0
while true do
task.wait(1)
addnumm += 1
TextOnScreen.Text = 100 - addnumm
addnum = addnum < goal and addnum or 0
end
local player = game.Players.LocalPlayer
local TextOnScreen = player.PlayerGui.ScreenGuiUntilSmushed.SmushText
local goal = 100
local addnumm = 0
while true do
task.wait(1)
addnumm += 1
TextOnScreen.Text = 100 - addnumm
addnumm = addnumm < goal and addnumm or 0
end
Edit: forgot another m, so recopy the script if you copied before the edit.