Why is this if statement not running?

I have this if statement that I think checks if allrooms has a string that matches a string in sessiondata[plr.UserId].Rooms (a table), but the if statement isn’t going through. Why?

sessiondata[plr.UserId].Rooms only contains the string “Stairs” right now, which matches the string in allrooms.

local allrooms = {["Stairs"] = workspace.StairsBlockade}

for i, v in pairs(allrooms) do
	if table.find(sessiondata[plr.UserId].Rooms, v) then
		v:Destroy()
	end
end

you’re searching for the workspace.StairsBlockade since you’re doing table.find(bleh, v) instead of table.find(bleh, i)

i had printed i and v, and both had returned the same thing last time i printed it, ill try this again though
update: tried it again, didnt change anything
update 2: nevermind, it didnt work because i also changed v:Destroy() to i:Destroy(), setting the find to i and destroy to v fixed it

the i and v are short for “index” and “value” respectively
the index of a table is like the key you need to obtain the value (usually just an increasing int [1, 2, 3, etc])

you can have multiple indexes lead to the same value, but you can’t have the same index lead to multiple values, if that makes sense

1 Like

yeah i understand that, im (kinda) new to scripting and have never needed to use index yet so this was a good learning experience, tysm for the help

1 Like

yeah thats alright.
there are gonna be a few gotchas to look out for when using dictionaries over tables (fancy vocab for a table with custom indexes), main one is that ipairs isn’t going to work and neither is the # operator to try and get a dictionaries length. somthn to keep in mind since i got stuck on those for a while

dont actually know what ipairs does yet, prob gonna review the documentation

1 Like

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