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

Why won't this script save my building? (datastore)

Asked by 4 years ago
local player = game.Players.LocalPlayer
local save = {}
local datastore = game:GetService("DataStoreService")
local store = datastore:GetDataStore("Buildings")

for i, v in pairs(script.Parent:GetChildren()) do
    if v:IsA("TextButton") then
    v.MouseButton1Click:Connect(function()
        if v.Name == "Save" then
            for i,v  in pairs(workspace:GetChildren()) do
                if v:IsA("BasePart") then
                    local partandCFrame = v.."!"..v.CFrame --ERROR HERE
                    table.insert(save, partandCFrame)
                end
            end
            store:SetAsync(player.UserId, save)
        else
            if store:GetAsync(player.UserId) then
                for i, v in pairs(store:GetAsync(player.UserId)) do
                    if v:IsA("BasePart") then
                        local newpart = Instance.new("Part", workspace)
                        newpart.Anchored = true
                        for i, v in pairs(string.split(v, "!")) do
                            if tonumber(v) then
                                newpart.CFrame = v
                            end
                        end 
                    end
                end
            else
                warn("NO SAVED DATA")
            end
        end
    end)
    end
end
0
What's the error? dadysherwin2 155 — 4y
0
Datastore can only store UTF-8 CHaracters, line 12 goodadmins 111 — 4y
0
I believe the issue is with you trying to store CFrame, I'll test it out in studio BuDeep 214 — 4y
0
SetAsync only works in server I think. RafaelFixe1 108 — 4y

Answer this question