So the datastore is not working, its suppose to save the values in my folder in the player, if the value is true then it means the player has the item. However nothing saves.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local Folder = ReplicatedStorage:WaitForChild("DataStore")
--functions--
local function GetDS(Value, Player)
local Data;
local DataFetchSuccess, ErrorMessage = pcall(function()
Data = myDataStore:GetAsync(Player.UserId.."-Inventory")
end)
if DataFetchSuccess then
if Data == nil and Value.Name == "DeafultKnife" or Value.Name == "DeafultFlashlight" or Value.Name == "Clown" then
Value.Value = true
elseif Data == nil and Value.Name == "Skin" then
Value.Value = "Clown"
elseif Data == nil and Value.ClassName == "StringValue" then
Value.Value = ("Deafult"..Value.Name)
elseif Data == nil and Value.ClassName == "BoolValue" then
Value.Value = false
elseif Data == nil and Value.ClassName == "NumberValue" then
Value.Value = 0
else
Value.Value = Data
end
end
end
local function SetDS(Value, Player)
local Data
repeat wait() until Data
local DataWriteSuccess, ErrorMessage = pcall(function()
Data = myDataStore:SetAsync(Player.UserId.."-Inventory")
end)
if not DataWriteSuccess then
local Retry = 0
while Retry < 6 do
wait(60)
local Succeded, Error = pcall(function()
Data = myDataStore:SetAsync(Player.UserId.."-Inventory")
end)
if Succeded then break end
Retry = Retry + 1
end
end
end
local function CheckChildren(Key, Children, Player)
for i = 1, #Children do
if Children[i].ClassName == "Folder" then
local C = Children[i]:GetChildren()
if C then
CheckChildren(Key, C, Player)
end
else
if Key == "GetDS" then
GetDS(Children[i], Player)
else
SetDS(Children[i], Player)
end
end
end
end
game.Players.PlayerAdded:Connect(function(Player)
--//Loading DataStores\\--
local Clone = Folder:Clone()
Clone.Parent = Player
local FolderChildren = Clone:GetChildren()
CheckChildren("GetDS", FolderChildren, Player)
-------------------
print("DataStore Loaded")
--CanSaveValue--
local CanSave = Instance.new("BoolValue",Player)
CanSave.Name = "CanSaveData"
CanSave.Value = true
end)
game.Players.PlayerRemoving:Connect(function(Player)
local Clone = Player:FindFirstChild("DataStore")
if Clone then
local CloneChildren = Clone:GetChildren()
CheckChildren("SetDS", CloneChildren, Player)
end
print("Saved DataStore")
end)