heres my code so far
local DSS=game:GetService("DataStoreService")
local SpeedData=DSS:GetDataStore("SpeedData")
local module = {}
local cache={}
function module.LoadData(Player)
local Success, Data=pcall(function()
return SpeedData:GetAsync(Player.UserId)
end)
cache[Player]=Player.leaderstats.Speed.Value
return cache[Player]
end
function module.SaveData (player)
local Data=cache[player]
print(Data)
if not Data then return end
pcall(function()
SpeedData:SetAsync(player.UserId,Data)
end)
end
return module
"
and this is my server script``lua
local Players=game:GetService('Players')
local dataHandler=require(script.datahandler)
local DataCache=dataHandler
Players.PlayerAdded:Connect(function(Player)
local leaderstats=Instance.new('Folder',Player)
leaderstats.Name='leaderstats'
local Speed=Instance.new('IntValue',leaderstats)
Speed.Name='Speed'
Speed.Value=dataHandler.LoadData(Player).Speed or 5
Speed.Changed:Connect(function()
local DataCache=dataHandler.cache
if DataCache[Player.UserId] then
DataCache[Player.UserId].Speed=Speed.Value
end
end)
end)
Players.PlayerRemoving:Connect(function(Player)
dataHandler.SaveData(Player)
end)```

