Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Value won't go above two?

So I'm trying to make a week counter which has a week that goes by every 4 seconds, and after 4 seconds the week number will go up. The number does rise, but it doesn't seem to go past 2.

local val = 1

local num = val + 1

script.Parent.Parent.Week.Text = "Week "..val

while true do
	script.Parent.Image = ""
	wait(1)
	script.Parent.Image = "rbxassetid://2759535970"
	wait(1)
	script.Parent.Image = "rbxassetid://2759536145"
	wait(1)
	script.Parent.Image = "rbxassetid://2759536271"
	wait(1)
	script.Parent.Image = "rbxassetid://2759536399"
	wait(1)
	script.Parent.Parent.Week.Text = "Week ".. num
	print(num)
	print(val)
end

I haven't done too much with number values, so thanks if you can help me out.

3 answers

✓ Accepted answer

I think you meant to put the num variable inside the loop so that it increases with each iteration:

local val = 1
script.Parent.Parent.Week.Text = "Week "..val

while true do
    val = val + 1
    script.Parent.Image = ""
    wait(1)
    script.Parent.Image = "rbxassetid://2759535970"
    wait(1)
    script.Parent.Image = "rbxassetid://2759536145"
    wait(1)
    script.Parent.Image = "rbxassetid://2759536271"
    wait(1)
    script.Parent.Image = "rbxassetid://2759536399"
    wait(1)
    script.Parent.Parent.Week.Text = "Week ".. num
    print(val)
end

2 comments

1

Well..You got the accepter answer..good  job, haha.

0

lol

Hi!

Your num variable is only incrementing once, as it is not in the While loop. If you put it in the While loop, it'll increment infinitly every 4 seconds.


local val = 0
while true do
    local num = val + 1
    script.Parent.Image = ""
    wait(1)
    script.Parent.Image = "rbxassetid://2759535970"
    wait(1)
    script.Parent.Image = "rbxassetid://2759536145"
    wait(1)
    script.Parent.Image = "rbxassetid://2759536271"
    wait(1)
    script.Parent.Image = "rbxassetid://2759536399"
    wait(1)
    script.Parent.Parent.Week.Text = "Week ".. num
    print(num)
    print(val)
end

2 comments

0

wow u hecking sniped me

0

bruh this wouldn't work because ur setting the variable val to 0 every time the loop

The problem is that you're only defining the next value once at the beginning. You have to set it in the loop so that it repeatedly goes up.

local num = 1

script.Parent.Parent.Week.Text = "Week "..num

while true do
    num = num + 1
    script.Parent.Image = ""
    wait(1)
    script.Parent.Image = "rbxassetid://2759535970"
    wait(1)
    script.Parent.Image = "rbxassetid://2759536145"
    wait(1)
    script.Parent.Image = "rbxassetid://2759536271"
    wait(1)
    script.Parent.Image = "rbxassetid://2759536399"
    wait(1)
    script.Parent.Parent.Week.Text = "Week ".. num
end

All you have to do is use one variable and change it's value in the loop. That way, it repeatedly goes up.

This discussion is preserved as it was. New answers, comments, and votes are closed.