Why is my datastore not saving?

For some context, Im trying to make a build saving system that saves a part relative to the plot, for some reason its not saving and i cannot find the error. I have the roblox api datastore thing on and its published to roblox.

I’m pretty sure that you can’t save Vectors to a database, probably applies to CFrames too.

1 Like

Addressing the Issue


You might wrap the :SetAsync(), :GetAsync()… etc. in pcall().

Also I thought storing whole DataModels are not possible. Consider about refraining from storing those. Instead, you could store relevant data about each object into the table and then store it. Woops, this was irrelavant.

Also CFrame are extremely long if you print out one. Ahahahaha!

Source: Saving parts/models via datastore?

1 Like

That’s actually what he already does.

1 Like

I just found out, my bad. Try the first paragraph.

1 Like

Instead of saving the CFrame value, could he save the Position and use Part.CFrame = Plot.CFrame * Vector3 ?

It could be both the position and the orientation, if the matrix thing is not necessary.

{position, orientation}

Or else this will be saved:
-6, 0.500001013, -11, 1, 0, 0, 0, 1, 0, 0, 0, 1

1 Like

Is it only me or this looks really wrong?
image
You’re deleting the player data.

You’re definitely completely right about that. It rarely happens, so it should be replaced with something else such as:

  • Disabling auto-saving
  • Kicking the player
  • Print out the error message for the players
1 Like

This is the datastore that I always use.

local Module = {};
local ServerStorage = game:GetService("ServerStorage")

function Module:Load(plr,folder,GDS,key)

    local Success,Data = pcall(GDS.GetAsync,GDS,key..plr.UserId);
    
    if not (Success) then
        plr.DataLoaded.Value = false;
        return;
    end

	if (Data == nil) then
        plr.DataLoaded.Value = true;
        return;
	end
    
    if (Success) then
        plr.DataLoaded.Value = true;
        for i,v in next,Data do
            if (folder:FindFirstChild(v.name)) then
                folder:FindFirstChild(v.name).Value = v.value;
            else
                warn(v.name.." is not valid member of "..folder.Name);
            end
        end
    end
end

function Module:Save(folder)
    local Data = {};
    for i,v in next,folder:GetChildren() do
        local TempData = {
            name = v.Name;
            value = v.Value;
        };
        table.insert(Data,TempData);
    end

    return Data;
end

return Module;
function PlayerLeft(Player)
	if (Player.DataLoaded.Value == false) then
		return
	end
	local Data1 = DataStoreModule:Save(ServerStorage[Player.Name]);
	local success,err = pcall(StatsData.SetAsync,StatsData,Key..Player.UserId,Data1);
end
1 Like

Also, there is no need to use pcall here
image
Instead of that you need to wrap SetAsync in pcall
image

Wrapping the function in protected call mode isn’t the issue. That’s only helpful if you want to catch errors. Typically you should wrap DataStore calls in pcall but that’s not what’s happening here.

The issue is that OP is trying to save a CFrame value to a DataStore. You can’t do this. You need to save the individual values to allow it to work (i.e. CFrame.X, CFrame.Y, CFrame.Z).

That’s because a CFrame is comprised of it’s coordinates and a rotation matrix.

1 Like