Trouble Calling Data From Tables

Hello. I was trying to make a script where there is a table, and if any of those things from the table are in the game, something is made invisible. I know mostly how to do it, but I don’t know how to make it so if anything in the table is in the game it happens. I only know how to make it for one. Here is the script.

maps = {"Map1","Map2","Map3","Map4"}

while true do
	wait(0)
	if game.Workspace.MapStorage:FindFirstChild(maps[]) then
    	game.Workspace.GoAway.Transparency = 1
    	game.Workspace.GoAway.GoAway2.Transparency = 1
    	game.Workspace.GoAway.Decal.Transparency = 1
		game.Workspace.Fall.CanCollide = false
	else
    	game.Workspace.GoAway.Transparency = 0
    	game.Workspace.GoAway.GoAway2.Transparency = 0
    	game.Workspace.GoAway.Decal.Transparency = 0
		game.Workspace.Fall.CanCollide = true
	end
end

Thanks for reading!

1 Like

Hi @jenae20!
There is a fairly simple way to solve this. To check if something that is in the table is in the game, a loop is required. Preferably a for loop.

local maps = {"Map1", "Map2", "Map3"}

    for i, v in pairs(maps) do
    	
    	if workspace.MapStorage:FindFirstChild(v) then
    		
    		--code
    		
    	else
    		
    		--code
    		
    	end
    	
    end

You are indexing the table maps with no index.

Try this:

for _, mapName in pairs(maps) do
	if game.Workspace.MapStorage:FindFirstChild(mapName) then
    	game.Workspace.GoAway.Transparency = 1
    	game.Workspace.GoAway.GoAway2.Transparency = 1
    	game.Workspace.GoAway.Decal.Transparency = 1
		game.Workspace.Fall.CanCollide = false
	else
    	game.Workspace.GoAway.Transparency = 0
    	game.Workspace.GoAway.GoAway2.Transparency = 0
    	game.Workspace.GoAway.Decal.Transparency = 0
		game.Workspace.Fall.CanCollide = true
	end
end

This will loop for each element in the table, one by one.

You must use FindFirstChild, otherwise it will give you an error if it doesn’t exist.

1 Like

I can’t seem to get this to work. I have no idea why it isn’t working.

There are no output errors. I tried adding a wait, but still nothing happened.

I just put those, and it seems to not be seeing the maps at all. I put one in the else, and one if it sees the maps, and it’s not seeing the maps.

I already tried that, and nothing different happened.

wait() has a minimum time, so wait(0) will wait the same amount of time as wait() would.

2 Likes

I made sure everything was spelt right, and they all were, but I found another way to make it work. I made it so it’s in a while true do loop, and if it sees the map, it waits the number of seconds the map stays to start checking again. I tried it without that last part, and it just flickered.

1 Like