Why is the function not finding the table?

I’m making a system that allows are user to spawn in multiple things at once, and when they put it into a table… the table has a name that you can use to query the function for it.

My issue is that it is not finding the item at all, even though their names are the exact same. What am I doing wrong?

image ← Proof that the names are the same.

Module

Settings.PresetSpawns = {
	["regular setup"] = {game.ServerStorage.Matchtypes.Stages["HIVE [1]"],game.ServerStorage.Matchtypes["Barriers & Walls"]["Invisible Walls [NJPW]"]}
	
}

Function

function PresetSpawners(PresetName:string, What2Do:string)
	if not Settings then error("NO SETTINGS FOUND") end
	
	if table.find(Settings.PresetSpawns,string.lower(PresetName)) then
		for _,Item in pairs(Settings.PresetSpawns[string.lower(PresetName)]) do
			Spawner(nil,What2Do,Item.Parent.Name,Item.Name)
		end
	else
		error("PRESET WAS NOT FOUND: Preset Name was "..string.lower(PresetName)) --[[This is the error I get every time I try to run the function]]
	end
end

replace the table.find() with Settings.PresetSpawns[string.lower(PresetName)]

1 Like

Thank you! Do you have any idea why the table.find part wasn’t working in this instance?

table.find() returns an index, not a boolean. So when you were using table.find() it was returning 1 (the index in this case). This expression if table.find(Settings.PresetSpawns, string.lower(PresetName) == 1 returns a boolean, which the script will recognise and proceed with. But you didn’t add that, so the script took it to be false and proceeded with the else

2 Likes

@Just2Terrify it’s been a long time, and I’m sorry for the wrong explanation by me 11 days ago. It’s not anything about returning indexes or booleans. table.find() is meant for arrays, not dictionaries and that is why it wasn’t working for you

1 Like

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