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 3 years ago
Edited 3 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?

game.Players.PlayerRemoving:Connect(function(Player)
    print('Saving Data For Player '.. Player.Name)

    -- Builds

    local BuildsValue = {}

    for i,v in pairs(game.Workspace.truc.PlacedObject:GetChildren()) do
        local cframe = v:GetPrimaryPartCFrame()
        print(cframe)
        local New = {['Object'] = v.Name, ['CFrameVal'] = cframe, ['I'] = v.WhereVal.Value}
        table.insert(BuildsValue,New)
    end

    local BuildEncode = HS:JSONEncode(BuildsValue)
    PlrDS:SetAsync("Builds-"..Player.UserId,BuildEncode)

end)
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 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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

{cframe:GetComponents()}

and then to get it back just do this:

table.unpack(cframe)

Hope this helped someone!

Ad

Answer this question