Why is this returning nil

image

Up there, i’m printing out a value and im returning the same exact value, but it still prints nil?

image

This is because island.Value == BestIslandValue is false. It seems like you’re unpacking a table full of integers and getting the max value. I believe Island.Value is a string therefore you cannot use math.max on it.

You’re not showing all your code (where was "Gym" printed?, what’s inside OwnedIslands?) and it’s also a screenshot so it’s hard to figure out what’s going on.

At the end, you call search which does return what you want, but you don’t return it to the parent function GetCurrentIsland.

Try changing

Search()

To:

return Search()

Now I expect there may be other problems, but this will fix your main one of the return value differing from the search return value.

Also, when formatting code, please use the ` 3 times before and after your code.

3 `

–Some code

3 `

Transforms into:

--Some Code