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

How can you make a delay?

Decided to rewrite this hopefully to make it more simple and understandable.

How can you make a second variable record the first variables values.

for example:

*Variable 1 starts setting to random numbers (ex/ 1,5,3,7,3)

variable 2 waits 1 second and then starts from the beginning of Variable 1 (ex/ 1,5,3,7,3)*

I don't want to set Variable 2 to the newest value of number of Variable 1

Sorry for confusion.

2 comments

0

Why would you use var 1 + 1 if it's already a for loop? It looks to me you're asking the wrong question, and you just need help on general aspects of coding.

0

I rewrote it to make a little more sense, hopefully you will under stand now. Sorry :)

3 answers

✓ Accepted answer

If you want var2 to be whatever var1 was 1 second ago, use this:

function SetVar1(value)
	var1 = value
	delay(1, function() var2 = value end)
end
SetVar1(5)

With this method, you never use "var1 = 5", you use "SetVar1(5)".

It doesn't need to be delayed a different way, wait() is fine, a for loop automatically adds 1 so you don't need the line var1 = var1+1, and you should probably define var2 before you start the loop.

try this:

local var2
for var1=1,5 do
    print ("var1   " ..var1.."")
    wait(3)
    var2 = var1
    print ("var2   " ..var2.."")
end

If you're trying to print "1,2,3,4,5", then all you need is a for loop. It looks to me you're just not sure how to use the loop.

for var1 = 1,5 do
print(var1)
wait(1)
end

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