Is it really worth using “–!strict”?
I am a solo developer making a little indie game. I came across type-checking and how I can use the “–!strict” mode a little bit ago. I talked around and it seemed like using it was the optimal choice for cleaner and more robust coding structures. Once I defined the –!strict mode at the top of my script, everything seemed fine. My scripts felt more controlled and professional. This was working great until I ran into a few problems. Type-check errors—are somehow worse than learning metamethods for the first time. The thing is, I never fully dived into learning type-checking. Yes, I spent time learning what I thought was most of it. But some type-errors I just couldn’t seem to fix. I knew that the –!strict mode would help with pointing out mistakes made by having the wrong type, but it felt like it went way deeper than that. When I first started to realize this wasn’t just some little mode you put on and then enjoy your day, was when it errored for not checking if a variable was nil or not. I had it set to variable: Instance. It wanted me to basically do: if variable == nil then return end. So I did it and went on with my day. BUT THEN, it got a little crazy. This is where I take you to the problem I’m facing right now.
Main Issue:
I’m scripting a procedural generation module at the moment. And I have a little table that deals with the paths at which the generation will take place. Since its a dictionary I use the metamethod “__len” to get the length of it when I need it. This is really annoying though since with arrays you can just add a hashtag to the front of the word without metamethods but whatever Roblox.
The problem is that, the “paths” table gets a type error on our last for loop (pictures of proof is provided).
Snippet of code:
--!strict
local ShipGen = {}
ShipGen.MetaTable = {
__len = function(tbl) -- gets length of table (usually a dictionary)
local num for i in tbl do num = i end return num
end,
}
local startRoom = GetStartRoom()
if startRoom == nil then return end -- check
local paths = {} -- the paths which will generate rooms
setmetatable(paths, ShipGen.MetaTable)
for i, exit in startRoom:GetChildren() do -- place the first exits into the path table thingy
if CC:HasTag(exit, "Exit") and exit:IsA("BasePart") then
paths[i] = exit -- I know I can just use "table.insert" but that wouldnt be a dictionary
end
end
print(#paths) -- > 2 (The __len metamethod works!)
for number, exit in paths do -- goes through all the possible paths (Type-checker underlines "paths" and errors it for some reason??)
end
return ShipGen
[REMINDER: This is not the entire module script, I’m just showing the code that is important and trying to save time with this]
And our friend “type-checker” doesn’t seem to like this last for loop I placed so it underlines the variable “paths”. It gives the following error:
![]()

Now to be completely honest. I have NO idea how to deal with this type error and what to do so I just kinda came to the dev forums. I most likely didn’t read far enough into how type-checking works and this is the result. I’m PRAYING someone can help me with this because if not I will never figure this out! If anyone needs clarifications on any part of this post I’d be happy to do so!
TL;DR:
If you’re too lazy to read allat, I get it. Hopefully this won’t be hard to understand if you’re a seasoned developer. But the problem i’m having is shown in the above image ^^^. I’m trying to fix a type error with an 80% confused and 20% sleep deprived brain. Reading that error is like trying to read another language. It’s erroring from a “paths” table (dictionary to be exact) I have which is using the __len metamethod. I don’t know how this could be erroring the paths table when im trying to use an iterate function but its happening somehow
.
Side Note:
I wrote this post at 2 am so if im a little unclear PLEASE ask me anything! Also feel free to correct some of my code if there are mistakes or better ways to do things. Fixing this type-error problem is high on my list.
Thanks Devs,
MonsterTrident
