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

[Answered] Datastore won't save CFrame?

Asked by 4 years ago
Edited 4 years ago

Hello, I was having a issue with the datastores. I wanted to save my model primary part CFrame, but when I go to the game again, the CFrameVall is null. Any idea how to fix this issue?

01game.Players.PlayerRemoving:Connect(function(Player)
02    print('Saving Data For Player '.. Player.Name)
03 
04    -- Builds
05 
06    local BuildsValue = {}
07 
08    for i,v in pairs(game.Workspace.truc.PlacedObject:GetChildren()) do
09        local cframe = v:GetPrimaryPartCFrame()
10        print(cframe)
11        local New = {['Object'] = v.Name, ['CFrameVal'] = cframe, ['I'] = v.WhereVal.Value}
12        table.insert(BuildsValue,New)
13    end
14 
15    local BuildEncode = HS:JSONEncode(BuildsValue)
16    PlrDS:SetAsync("Builds-"..Player.UserId,BuildEncode)
17 
18end)
0
might be worth splitting up the compnents of the cframe and save them as float/number values. though that would bloat your script a little. Look at https://developer.roblox.com/en-us/api-reference/datatype/CFrame @ the bitCFrame:GetComponents ( ) function section TGazza 1336 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Hello, I found out how! I just needed to put the CFrame in a table just like this:

1{cframe:GetComponents()}

and then to get it back just do this:

1table.unpack(cframe)

Hope this helped someone!

Ad

Answer this question