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

How can I make this loop repeat every 1 second?

Asked by 8 years ago

Once I run through this script in test mode, there are no errors. The script still does not work though. What am I doing wrong?

local plr = game.Players.LocalPlayer
local g = plr:WaitForChild'stats'
local timemax = g:WaitForChild('timemax')
local countdown = g:WaitForChild('countdown')
local loaded = g:WaitForChild('loaded')

for i = 1,25 do
countdown.Value = countdown.Value +1
script.Parent.Size = UDim2.new(countdown.Value/timemax.Value,0,1,0)
wait(1)
end
if countdown.Value == 60 then
loaded.Value = true
end

The script is in a LocalScript and It is supposed to add 1 to the countdown value every 1 second, then when the countdown's value is 60, the "loaded" value is true. Which will complete the loading sequence in my game. Thank you for the help!

1
Did you forget Parenthesis when you set the variable for 'g'? KingLoneCat 2642 — 8y
0
Parenthesis should be fine, they're not always needed. Most of the time parenthesis are completely optional. User#11440 120 — 8y

2 answers

Log in to vote
1
Answered by
guiraz 25
8 years ago
Edited 8 years ago
  1. make sure the names of the objects you get using WaitForChild("") are correct

  2. try adding a print("") after each :WaitForChild("") to make sure you spelled it right

0
Adding a print after using WaitForChild is completely useless. If the object WaitForChild is looking for doesn't exist, the script will never print the print statement because it's still waiting for the object. User#11440 120 — 8y
0
Thank you for helping realize I had "timemax" instead of "maxtime" Lol. kingstephen23 35 — 8y
Ad
Log in to vote
0
Answered by
StoIid 364 Moderation Voter
8 years ago
Edited 8 years ago

add wait(1) after for i = 1,25 do

for i = 1,25 do
wait(1)
0
What would that do? User#11440 120 — 8y

Answer this question