Make load folders script (server script inside workspace)
local DataStore = game:GetService("DataStoreService")
local function decodeCFrame(cf)
return CFrame.new(unpack(cf))
end
game.Players.PlayerAdded:connect(function(plr)
local player = plr
local Saves = player:WaitForChild("Saves")
local savesAmount = Saves:WaitForChild("SavesAmount")
local num = 0
local SavesAMBackup = savesAmount.Value
wait(2)
if savesAmount.Value > 0 then
repeat
local keyStore = DataStore:GetDataStore("keyStore "..num)
local PosData = DataStore:GetDataStore(tostring("CFrameDataStore "..num))
print(PosData)
if keyStore ~= nil and PosData ~= nil then
local key = keyStore:GetAsync(player.UserId) or false
wait()
num = num + 1
SavesAMBackup = SavesAMBackup - 1
local folder = Instance.new("Folder")
folder.Name = num
folder.Parent = player.Saves
local keyFolder = Instance.new("BoolValue")
keyFolder.Name = "key"
keyFolder.Value = key
keyFolder.Parent = folder
local CFramePacked = (PosData:GetAsync(player.UserId))
print(CFramePacked)
local CFrameUnpacked = (decodeCFrame(CFramePacked))
local PlayerPosition = Instance.new("CFrameValue")
PlayerPosition.Name = "PlayerCFrame"
PlayerPosition.Value = CFrameUnpacked
PlayerPosition.Parent = folder
else
print("datastore nil")
end
until SavesAMBackup <= 0
else
warn("no saves")
end
end)
Problem is that Posdata is printed as 'nil' however, this 'if keyStore ~= nil and PosData ~= nil then' doesn't detect it being nil because it still gives an error with unpacking the CFrame values, these are the other (linked) scripts
Folder save script (module script inside workspace)
local DataStore = game:GetService("DataStoreService")
key = false
local module = {}
local num = 0
local function encodeCFrame(cf)
return {cf:components()}
end
local function decodeCFrame(cf)
return CFrame.new(unpack(cf))
end
function module.save(player, PosData)
print("SAVING")
print(player, PosData)
num = 0
for index, save in pairs(player.Saves:GetChildren()) do
if save:IsA("Folder") then
num = num + 1
end
end
local Save = Instance.new("Folder")
Save.Name = num + 1
Save.Parent = player.Saves
local PlayerCFrame = Instance.new("CFrameValue")
PlayerCFrame.Name = "PlayerCFrame"
PlayerCFrame.Value = player.Character.HumanoidRootPart.CFrame
PlayerCFrame.Parent = Save
key = true
player.Saves.SavesAmount.Value = player.Saves.SavesAmount.Value + 1
local keyStore = DataStore:GetDataStore("keyStore "..num)
local CFrameDataStore = DataStore:GetDataStore(tostring("CFrameDataStore "..num))
print("saving")
keyStore:SetAsync(player.UserId, key)
CFrameDataStore:SetAsync(player.UserId, encodeCFrame(PlayerCFrame.Value))
local var = (CFrameDataStore:GetAsync(player.UserId))
print(decodeCFrame(var))
end
return module
(no errors from this script, even the getasync seems to work fine)
Save to module manager (server script (fires on a server event fired by a local script inside startergui (playergui)) inside workspace)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SaveGame = ReplicatedStorage:WaitForChild("SaveFullGame")
local moduleSaver = require(workspace.DataStore.SaveScript)
SaveGame.OnServerEvent:connect(function(player)
local char = player.Character or player.CharacterAdded:wait()
if char then
local HRP = char:WaitForChild("HumanoidRootPart")
local CFrameData = HRP.CFrame
moduleSaver.save(player, CFrameData)
end
end)
No errors from this either, works fine
Savesamount script (server script inside workspace)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStore = game:GetService("DataStoreService")
local SavesList = DataStore:GetDataStore("SavesList")
local Save = ReplicatedStorage:WaitForChild("SaveGame")
game.Players.PlayerAdded:connect(function(player)
local Saves = Instance.new("Folder",player)
Saves.Name = "Saves"
local SavesAmount = Instance.new("IntValue",Saves)
SavesAmount.Name = "SavesAmount"
SavesAmount.Value = SavesList:GetAsync(player.UserId) or 0
SavesList:SetAsync(player.UserId, SavesAmount.Value)
print(SavesAmount.Value,SavesList:GetAsync(player.UserId))
SavesAmount.Changed:connect(function()
SavesList:SetAsync(player.UserId, SavesAmount.Value)
end)
end)
local function save(player, SavesAM)
SavesList:SetAsync(player.UserId, player.Saves.SavesAmount.Value)
end
Save.OnServerEvent:Connect(save)
Last ones work fine, only the first one really matters but I wanted to be sure xD
