I’m trying to make a rock spawning system that gets the rock’s properties from a dictionary but am encountering issues with a nil value.
Whenever the ‘rockType’ is defined at the start, the system somewhat works (but only spawns that rock type), but when I leave it empty, the ‘rockTypes[rockType].size’ becomes nil. It’s like it’s avoiding the if-statement that defines the ‘rockType’ right after.
(‘rockTypes’ is the dictionary, ‘rockType’ is a string value defining each element within)
Any idea what I’m missing? (screenshots below)
Roblox doesn’t make logic errors. In the second screenshot where you leave rockType as undefined, its value is determined by the spawnType and random variables. Your issue here is that spawnType is simply not equal to 1.
You should add a print inside the if spawnType == 1 then code block to confirm that the if statement is being passed. And add more prints in the nested if and else statement code blocks.
I printed the spawnType and it’s in fact 1. It’s a value that’s stored as attribute in the rock model itself, currently there only is 1 but I plan to add more later.
Since 1 and "1" are different types, there’s no way they are equal.
Some coding languages with less restrictions like JavaScript do allow this type of comparison being true, which is why they most likely also have a === comparer which checks if they’re the same value AND type. This is more confusing that Lua, though.