This datastore is fully functional as far as i can tell. I've looked over the code a few times and either my eyes are just sick of looking at it. or i just don't know what the error is. either way. the save function isnt saving the new values i put in to be saved
---- SERVER
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("ey3eyekjgyyeyeye")
local DataHandler = require(game:GetService("ServerStorage"):WaitForChild("Modules"):WaitForChild("PlayerDataManager"))
game:GetService("Players").PlayerAdded:connect(function(player)
--Create Data PlaceHolders
local lead = Instance.new("Folder", player)
lead.Name = "leaderstats"
local test = Instance.new("IntValue", lead)
test.Name = "test"
--Retrieve Data
DataHandler.GetData(player, ds, test)
print("Data Retrieved")
--Autosave Data
while wait(--[[60 * 5]] 20) do
print("Autosaving...")
DataHandler.SaveData(player, ds)
print("Autosave Sucessful!")
end
end)
--Save Data on Player Left
game:GetService("Players").PlayerRemoving:connect(function(player)
DataHandler.SaveData(player, ds)
end)
---- MODULE
local DataHandler = {}
local Stats = {}
local DefaultStats = {50}
function DataHandler.GetData(player, ds, test)
pcall(function()
Stats = ds:GetAsync(player.UserId)
end)
if Stats then -- Check to see if they have played the game and have a entry in data store.
--load stats
test.Value = Stats[1]
print("Loading Data...")
else -- If they dont have data created then create data.
Stats = DefaultStats
print("Creating New Data...")
end
end
function DataHandler.SaveData(player, ds)
ds:SetAsync(player.UserId, Stats)
print("Saving Data...")
end
return DataHandler |