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?
01 | DATA = game:GetService( "DataStoreService" ):GetDataStore( "OINSDHLSJHG" ) |
03 | game.Players.PlayerAdded:connect( function (plr) |
04 | local t = Instance.new( 'StringValue' ) |
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 |
12 | plr:WaitForDataReady() |
13 | if DATA:GetAsync(plr.userId) then |
14 | local models = DATA:GetAsync(plr.userId) |
15 | for _,v in pairs (models) do |
16 | if plr.Tycoon.Value ~ = "" then |
17 | local baseplate = workspace:FindFirstChild(plr.Tycoon.Value).Base |
18 | local createdModel = game.ReplicatedStorage.Objects:FindFirstChild(v [ 1 ] ):Clone() |
19 | local offset = Vector 3. new(v [ 2 ] [ 1 ] ,v [ 2 ] [ 2 ] ,v [ 2 ] [ 3 ] ) |
20 | createdModel:SetPrimaryPartCFrame(CFrame.new(baseplate.Position + offset)) |
21 | print ( "Hello" ..baseplate) |
27 | game.Players.PlayerRemoving:connect( function (plr) |
28 | plr:WaitForDataReady() |
29 | if plr.Tycoon.Value ~ = "" then |
30 | local tycoon = workspace:FindFirstChild(plr.Tycoon.Value) |
31 | local baseplate = tycoon:FindFirstChild( "Base" ) |
33 | for _,v in pairs (tycoon:GetChildren()) do |
34 | if v:IsA( "Model" ) and v.PrimaryPart then |
35 | local offset = v.PrimaryPart.Position - baseplate.Position |
36 | table.insert(models, 1 , { v.Name, { offset.X,offset.Y,offset.Z } } ) |
Thanks!