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

What does a % do in a script?

So I was looking at the Snack Break problems created by Sukinahito. I looked at his solution for Snack Break #1, and his answer included % marks which I didn't even know what they did in Lua.

What do % marks even do in ROBLOX Lua?

Sukinahito's script in question:

local results = { }
for index = 1, 100 do
	if index == 0 then
		results[index] = "FizzBuzz"
	elseif index%3 == 0 then
		results[index] = "Fizz"
	elseif index%5 == 0 then
		results[index] = "Buzz"
	else
		results[index] = index
	end
end
print(table.concat(results, "\n"))

1 answer

✓ Accepted answer

A "%" in Lua and many other languages is an operator that preforms the modulus operation. What it does it finds the remainder of the division of two values. The remainder is simply what is left over after completing division (see this image if this description wasn't clear enough).

4 comments

0

So if I put in print(9%4) in a script, 1 is what appears in the output?

0

Yes, because that's what would remain if you divided 9 by 4.

0

Correct as 4 goes into 9 twice with 1 unit left over

0

Awesome, thanks.

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