Table not working?

Hi, i have a very big problem so i can’t continue making my game

Basically the value that i set to table is nil ;/
There’s nothing that i could say so there are screenshots:

Set the value, fire the function

Function

Output

Help pls, i have no idea what i did wrong

you can’t insert a nil value into an array

Yes you can. Try this in studio: print(({nil, nil, 5})[3])

3 Likes

i’ve even changed it to workspace.Baseplate and still nothing

Can you show the full error message? You might be calling the function somewhere else without realizing it. You can also ctrl+f for any other calls if you prefer.

2 Likes

my bad, was basing that off of the api page

1 Like

Since you are setting smallest to false when you ‘return false’, the following calls on getSmallestBlock() will send ‘false’ instead of an array. It’ll then error as you can’t index [2] of false.

2 Likes

Is line 55 the first or second call to getSmallestBlock? I think what’s happening is that it’s being put inside the alreadyCheckedTable the first time you call the function and the second time it won’t return anything since alreadyChecked would be true.

2 Likes

first call is in line 55

30 characters

i deleted
return false
and still nothing

The only way it could return nil is if alreadyChecked is true, so that’s probably the issue. Out of curiosity, why does it matter if it’s already been checked?

3 Likes

Deleting ‘return false’ won’t fix it either, if nothing is returned then smallest will merely be set to nil.

I.e. This will print nil.

local test = true

local function run(val)

end

test = run(test)

print(test)

because if 1 block gets checked then it can’t get checked next time

the alreadyChecked returns false, i checked it using print

Where do you check it? I don’t see any other way this could be returning nil, so I’m out of ideas. Try printing after the second end if that’s not where you already tried.

A potential fix could be this:

-- instead of this:
if true then
	smallest = whatever
end
-- do this:
smallest = getSmallestBlock(block, smallest) or smallest
2 Likes

I checked it before

30 characters

okay thanks it works