I have a map system in my game where a map is loaded into a model called "Map" inside workspace. My maps are named Map1, Map2, Map3, etc. I need to get the actual map inside the map object so that I can clone something that's inside of that. How can I write code that works for all of my maps, no matter what the name is? Thanks in advance.
This seemed fun so I thought I'd answer it.
This script will be made with the above in mind.
local storage = game:GetService("ReplicatedStorage") function SpawnMap(MapNum) for _, Maps in pairs(storage:GetChildren()) do local MapToSpawn = "Map" .. MapNum if Maps.Name == MapToSpawn then Maps:Clone().Parent = workspace local MapObjects = Maps:GetChildren() for _, MapObject in pairs(MapObjects) do if MapObject.Name == "PlayerStartDoor" then local PlayerStartDoor = MapObject PlayerStartDoor.Lock = true -- Door is now locked end end end end end
This scripts spawn a map of your choosing.
SpawnMap(1)
This will spawn Map1
when Map1 spawns the script will look for the door and lock it.
Loops are fun.