hey! my datastore doesnt save some help me fix this problem thanks.
heres the script
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("PlayerData")
function module:DataStoreServiceSave(player,dataable)
warn("Active the module function")
local succes , err =pcall(function()
MyDataStore:SetAsync(player.UserId,dataable)
end)
if succes then
print("WARN")
else
error(err)
end
game.Players.PlayerRemoving:Connect(function(plr)
local SettingTable = {
Fruit = plr.Settings.Fruit.Value;
}
warn("The player left")
local SettingTable = {
Fruit = plr.Settings.Fruit.Value;
}
DataSaver:DataStoreServiceSave(plr,SettingTable)
end)
local DataSaver = require(script:WaitForChild("DataSaver"))
game.Players.PlayerAdded:Connect(function(plr)
local Total = Instance.new("Folder")
Total.Name = "Settings"
Total.Parent= plr
local a = Instance.new("StringValue")
a.Name = "Fruit"
a.Value = "None"
a.Parent=Total
local succes, data = DataSaver:DataStoreServiceLoad(plr)
if succes then
print(data.Fruit)
warn("Succesfully load"..tostring(succes))
a.Value = data.Fruit
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local SettingTable = {
Fruit = plr.Settings.Fruit.Value;
}
warn("The player left")
local SettingTable = {
Fruit = plr.Settings.Fruit.Value;
}
DataSaver:DataStoreServiceSave(plr,SettingTable)
end)
Make sure there’s spaces between the words and the =.
Use protective call to make sure your script doesn’t work after an unexpected error happening in DataStore.
local success, result = pcall(function()
result = DataSaver:DataStoreServiceLoad(plr)
end)
if success then
— use result to load data.
else
— use result to print our error code.
end