I have been working on a game called Maniacal Mechanics, and it is very bland currently. One of many reasons for that is that there is only one map. I would like to change that, the only issue is that I don’t know how to load and unload maps. I’ve tried looking up the load()
command in the Roblox API, but all that the page says is “Loads a model from an ID/Link,” which is not helpful whatsoever. I’m sure someone knows how to do this, but please don’t outright tell me how. I would just like to know the basic idea of what to do so that I can work from there.
Couldn’t you encase your Map Loading in a loop, reference all of your maps using the GetChildren()
function, then select a random map to load & after a couple of minutes unload then load another random map?
The issue is that I don’t know how to load things…
Try InsertService:LoadAsset()
instead of using load() if trying to load something at runtime. I’ve had more success with this.
My main issue with load()
is that I can’t really choose where the model actually loads in. Models for some reason don’t have a position
property, and I’d rather not have scripts that load in each individual part in their specified place.
Ahhh okay, my bad.
Models have a built in :MoveTo method, regardless of whether they have a PrimaryPart or not. You can just call :MoveTo on the model and move it to a given V3. Keep in mind that this also takes into account collisions.
If you’re trying to move the model into a building or something indoors in which :MoveTo may not give the desired effect, you may want to consider using :SetPrimaryPartCFrame instead. Assuming the model doesn’t have a PrimaryPart, you can create one by using the model’s :GetBoundingBox method.
Ok, I’ve worked everything into my code, but I haven’t tested it yet because of one thing.
I don’t know how to unload models.
After a quick scroll through the Roblox API and a search on the DevForums, I can confirm that I have absolutely no clue on what I’m doing.
How do you unload models?
To unload models, you can:
A) parent them to Replicated or ServerStorage
or
B) Destroy them (going to require you to load them every time)
Nice! I should have everything done now code-wise, I just have to test it.
EDIT: After some strange tweaking, it all worked! Thanks for the help!
Maybe just store maps in server storage and have them load in and out between the workspace. If they are big, have them load in chunks like PolyBattle
You can clone the map and parent it to the workspace, then destroy it afterwards