I am making a map system where different players can play different in different maps, but in the same server. When they want to play a specific map I want to load the map from serverstorage, and put it into workspace. When I put it into workspace I want it to move the whole thing to a space further away from other maps. This is because if more than one player choose the same map, the maps will be merged inside eachother. The problem I’m having with :ToObjectSpace() and :ToWorldSpace(). For some reason the map just breaks.
Here is my code:
local mapFolder = Instance.new("Folder", workspace.Bosses)
mapFolder.Name = "Hobo"
local assetFolder = Instance.new("Folder", mapFolder)
mapFolder.Name = "map"
local base = hoboMap.map.base:Clone()
base.Parent = assetFolder
for _, part in pairs(hoboMap.map:GetDescendants()) do
if part:IsA("BasePart") and part.Name ~= "base" then
local newPart :BasePart = part:Clone()
local offset = newPart.CFrame:ToObjectSpace(base.CFrame)
newPart.CFrame = offset:ToWorldSpace(base.CFrame)
newPart.Parent = assetFolder
end
end
I loop through the whole map folder and move each part to the base of the map.
Here is what the map is supposed to look like:
Here is what the script does:
The grey square on the left is the base.
I know I can weld everything together and move them by the primarypart in a model. But, the problem with that is it would maybe cause some lag. Am I right? Even if that is not the case, I would like to make it work using the offsets and cframes, because I want to understand them. Also because I am stubborn. I think it is a pretty easy solution, I just dont have experience with CFrames. Thanks!