What do you want to achieve?
I’m trying to Datastore the players data on a ModuleScript
What is the issue?
It doesn’t save the data I even went on DataStore Editor to check if it saves
What solutions have you tried so far?
I played the game and went to console and wrote the script but it didn’t save
DataStoreModule
local DataStoreService = game:GetService("DataStoreService")
local DataStore1 = DataStoreService:GetDataStore("LeaderstatsData")
local DataStore2 = DataStoreService:GetDataStore("MultipliersData")
local DataStore3 = DataStoreService:GetDataStore("SettingsData")
local DataStore4 = DataStoreService:GetDataStore("CodesData")
local SaveDataModule = {}
function SaveDataModule:LeaderstatsGet(LocalPlayer)
local LeaderstatsData
local success, err = pcall(function()
LeaderstatsData = DataStore1:GetAsync(LocalPlayer.UserId)
end)
if success then
LocalPlayer.Leaderstats.Bits.Value = LeaderstatsData[1]
LocalPlayer.Leaderstats.Tokens.Value = LeaderstatsData[2]
LocalPlayer.Leaderstats.Time.Value = LeaderstatsData[3]
LocalPlayer.Leaderstats["Accessories Collected"].Value = LeaderstatsData[4]
print("LeaderstatsData GetAsync")
else
warn(err)
print("No data found in player!")
end
end
function SaveDataModule:LeaderstatsSet(LocalPlayer)
local TableCode = {
LocalPlayer.Leaderstats.Bits.Value,
LocalPlayer.Leaderstats.Tokens.Value,
LocalPlayer.Leaderstats.Time.Value,
LocalPlayer.Leaderstats["Accessories Collected"].Value,
}
local success, err = pcall(function()
DataStore1:SetAsync(LocalPlayer.UserId, TableCode)
end)
if success then
print("LeaderstatsData SetASync")
else
warn(err)
end
end
return SaveDataModule
SetLeaderstatsModule
local SetStatsModule = {}
function SetStatsModule:Leaderstats(LocalPlayer)
local Leaderstats = Instance.new("Folder", LocalPlayer)
Leaderstats.Name = "Leaderstats"
local Stat1 = Instance.new("NumberValue", Leaderstats)
Stat1.Name = "Bits"
local Stat2 = Instance.new("NumberValue", Leaderstats)
Stat2.Name = "Tokens"
local Stat2 = Instance.new("NumberValue", Leaderstats)
Stat2.Name = "Time"
local Stat3 = Instance.new("NumberValue", Leaderstats)
Stat3.Name = "Accessories Collected"
end
return SetStatsModule
Script(Parent is ServerScriptService()
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ScriptFolder = ReplicatedStorage:WaitForChild("Scripts", 1)
local ModuleFolder = ScriptFolder:WaitForChild("Module", 1)
local SetStatsModule = require(ModuleFolder.SetStatsModule)
local SaveDataModule = require(ModuleFolder.SaveDataModule)
Players.PlayerAdded:Connect(function(LocalPlayer)
local success, err = pcall(function()
SetStatsModule:Leaderstats(LocalPlayer)
SaveDataModule:SetLeaderstats(LocalPlayer)
end)
if success then
print("Done!")
else
warn(err)
end
end)
Players.PlayerRemoving:Connect(function(LocalPlayer)
local success, err = pcall(function()
SaveDataModule:LeaderstatsSet(LocalPlayer)
end)
end)
game:BindToClose(function()
for i, plrs in pairs(Players:GetChildren()) do
local success, err = pcall(function()
SaveDataModule:LeaderstatsSet(plrs)
end)
end
end)