Can someone help me understand how theses two lines of code work?

Hello, I’m bad at maths, if someone could help me understand how “t” works because I’m a bit lost.

local cycleTime = 2
local t = (workspace.DistributedGameTime)%cycleTime
print(t)

So with theses two lines it go to 2 then go back to 0 then go to 2 etc…

But if i do :

print(workspace.DistribuedGameTime) 

Then the time just go from 0 to like 50 if i stay 50 seconds in the game, without go back to 0.

I don’t understand how with the first two lines of code, why the number go back to 0 (then go back 2 etc…) ?

I’m sorry I’m having trouble being understood this is not my native language and I’m really bad at maths.

Thank you very much any help is apprecied

basically, modulo gets the remainder of a division statement. (3 modulo 2 is 1 for obvious reasons). so, when the time gets to 2, the remainder will be 0. and for every multiple of 2 the time reaches; the remainder will be 0.

1 Like

I’m sorry, I don’t understand at all. Isn’t there a way to explain this in very simple words (as if you were explaining to a 6 year old :sweat:)? That would help me a lot

modulo gets the remainder of division. we’re getting the remainder of DistributedGameTime and cycleTime (which is 2). we know 4 / 2 has no remainder. we know 6 / 2 has no remainder. so, the t value will be 0 if DistributedGameTime is a multiple of 2. (a multiple of 2 is 2, 4, 6, 8, etc.)

edit: the modulo operator is the % sign or the percentage sign.

1 Like

Okay, thank you, I’ll try to meditate on these words to understand their essence. Thanks again for your help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.