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:
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!
I'm relatively new to scripting as well, not as new as you are, but still new enough that I don't have a clue what . . .
if string.find(map, "Map1") then
does, but you might have forgotten to ask if the name of the part is the same as the string. Here's an example:
if game.Workspace.Block.Name == "StringNameHere" then -- Make sure to always include that you're asking about the name of the part, and not the part. -- Anything you want it to do in here. end
Sorry that I don't know what that line necessarily means, but according to the error anyway, the problem is you're asking if the object itself is equal to a string, which results in an error.
Edit: Couldn't you just do . . .
if map.Name == "Map1" then -- Teleport to map1 code here elseif map.Name == "Map2" then -- Teleport to map2 code here end
Make a folder called maps instead, and make a models called spawns in the maps and you put parts in it.
local Maps = game.ServerStorage.Maps:GetChildren() local RandomMap = Maps[math.random(1,#Maps)] print(RandomMap.Name) local Spawns = RandomMap:WaitForChild("Spawns"):GetChildren() for _, v in pairs(game.Players:GetPlayers()) do if v.Character then local Spawn = Spawns[math.random(1,#Spawns)] local Character = v.Character:MoveTo(Spawn.Position) end end