Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Saving And Loading A Grid Placement Systems Assets?

Asked by 7 years ago
Edited 7 years ago

Hey. Ive been wanting to make a grid placement sandbox tycoon, but im not sure how to save models locations in the base. What im mainly unsure of is how to save all the instances positions and load them all in one datastore, would i do it all in one table? how would i know how many objects are being loaded? Or am i overcomplicating this? Any help is appreciated, thanks!

Ive been given the idea of this script but through testing it doesnt seem to be working and comes up with no errors. Do i need to enable save place api?

01DATA = game:GetService("DataStoreService"):GetDataStore("OINSDHLSJHG")
02 
03game.Players.PlayerAdded:connect(function(plr)
04    local t = Instance.new('StringValue')
05    t.Name = "Tycoon"
06    t.Parent = plr
07    if workspace["Tycoon A"].Owner.Value == "" then
08        local baseplate = workspace["Tycoon A"].Base
09        plr.Tycoon.Value = "Tycoon A"
10        workspace["Tycoon A"].Owner.Value = plr.Name
11    end
12    plr:WaitForDataReady()
13    if DATA:GetAsync(plr.userId) then
14        local models = DATA:GetAsync(plr.userId)
15        for _,v in pairs(models) do
View all 41 lines...

Thanks!

0
Also i dont currently have a placement system made as i wont bother if i dont end up knowing how to save the thing :P MezzaBlockGuy 2 — 7y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
7 years ago

You can just iterate through the models in the base and record their name and offset from the baseplate’s position (or some other core part that every tycoon has). Then, you would iterate through the loaded table, create the models and offset them from the baseplate position to return them to the same place. You would have to give all models a PrimaryPart so that you can move it as one, and put a copy of every model in ServerStorage.

Recording model positions:

01local tycoon = --set to tycoon model
02local baseplate = tycoon:FindFirstChild("Baseplate") --set to tycoon baseplate
03local models = {}
04for _,v in pairs(tycoon:GetChildren()) do
05    if v:IsA("Model") and v.PrimaryPart then
06        local offset = v.PrimaryPart.Position - baseplate.Position
07        table.insert(models,1,{v.Name,{offset.X,offset.Y,offset.Z}})
08    end
09end
10--save models table

Loading model positions:

1local models = --loaded tycoon models
2for _,v in pairs(models) do
3    local createdModel = game.ServerStorage:FindFirstChild(v[1]):Clone()
4    local offset = Vector3.new(v[2][1],v[2][2],v[2][3])
5    createdModel:SetPrimaryPartCFrame(CFrame.new(baseplate.Position + offset))
6end
Ad

Answer this question