I don't understand this block of code does

Can somebody explain how this if expression works, or what lock does? And is there anyway It can be written simpler?

-- this code is on line 47 in wheel main, It handles the input for the hsv wheel
if 
		if lock then (m < 0.8) else (not huewheel)
		then
		-- mouse in inner circle
	elseif
		if lock then (m < 1) else (huewheel) then
		-- mouse in hue wheel
	end

I am not familiar with this kind of “if expression”

the placefile where the code lies is here: colorwheel (1).rbxl (32.5 KB)
on line 47 in WheelMain

It’s just checking whether lock is a truthy value before proceeding


These are called if-then-else expressions. It’s Luau’s ternary operator:

local bool = true
local value = if bool then "Yay!" else "Nay!"

print(value) --> prints "Yay!"

In the code example, the example checks if bool is a truthy value, then it evaluates to the given values:

-- what this looks like using a normal if-then expression

local bool = true
local value;
if bool then
   value = "Yay!"
else
   value = "Nay!"
end

print(value) --> prints "Yay!"
1 Like

just like @HugeCoolboy2007 said.

also for more info: Intro to If Statements | Documentation - Roblox Creator Hub