Purpose of using colons with parameters

What’s the purpose of using colons " : " with parameters of functions?
image

You’re just declaring the data type of each parameter you’re sending in. In Lua, you don’t need to do this. In other languages, you do.

It does improve readability, but like I said above, it isn’t necessary in Lua.

Something important to note is that if you do declare the expected parameter type, it will not halt/error/log anything in the output if you send the wrong data type. So you could have local numberOne:number = "This isn't a number!" and it wouldn’t log any output. You can verify parameter types using typeof().

You can also put a : at the end of a function if you want to declare what return types will be returned.

local function something(parameter1:string, parameter2:number): (string)
    return tostring(parameter1..parameter2)
end
2 Likes

In Roblox, using colons “:” with parameters in function definitions helps clarify the expected types of parameters, improving code readability and enabling better error checking during development.

1 Like

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