Hi, I'm currently having a problem where my 'if statement' doesn't detect the name of the map and instead just prints the error.
I'm relatively new to Lua (have been working on it for a couple of weeks now) and might just have overlooked something very simple here.
I would very much appreciate if anyone could fix this as it looks like it should work to me:
- The error I get is as follows: bad argument #1 to 'find' (string expected, got Object)
I have tried doing if map == "Map1" but this does not work either
(my function MovePlayers does work as I've tested it outside of the if statement so that's not the issue)
local num = math.random(1,2)
local map = game.ServerStorage:WaitForChild("Map" ..num)
map:clone().Parent = game.Workspace
print(map)
if string.find(map, "Map1") then
MovePlayers(Vector3.new(1129.8, 0.5, -6.1), Vector3.new(928.2, 0.5, 183.7), Vector3.new(784.1, 0.5, -86.3))
elseif string.find(map, "Map2") then
MovePlayers(Vector3.new(1129.8, 0.5, -6.1), Vector3.new(928.2, 0.5, 183.7), Vector3.new(784.1, 0.5, -86.3))
else
error("No map found")
end
Thanks for any help offered!

8 comments
Hope I helped at least a little bit!
Hi, yeah I used that string.find because I've been trying to fix this for a while now and really can't seem to get it, the problem is I can't just use the block's name as it's cloned in and might be different each time, this is similar to what you are suggesting but still doesn't work, really out of ideas!: if game.Workspace["Map"..num] == "Map1" then
I might be able to help you a little better if I knew what you're trying to do.
Basically I have 2 models (maps) in the Server Storage and it selects one randomly by adding the random number to "Map", this is then cloned into the game and it is in the workspace as either Map1 or Map2, I'm basically trying to detect which one was selected and based on that it changes where the players are teleported into the maps, as they are different (right now the locations are the same)
FIXED IT! Damn your post did actually help a lot! I hadn't put .Name after if game.Workspace["Map"..num] which meant it wasn't the name of the part it was comparing, I can't thank you enough man! I'd upvote you if I could!
Oh, and I just put an edit showing what you could do xD.
Yeah it's annoying when I don't know these little things in lua that make life so much easier haha, but I'm learning. Anyway thanks for your help again man and good luck with your own lua ability!
Thanks, you too!