I have made this module thing for storing player data
please give feedback for changes or something as I am unexperienced with datastores
local dserv = game:GetService("DataStoreService")
local plrstore = dserv:GetDataStore("SimplySavePlr")
local plrs = game:GetService("Players")
local ver = game.ReplicatedStorage.Version.Value
local plrdata = {}
plrs.PlayerAdded:Connect(function(plr)
local result = plrstore:GetAsync(tostring(plr.UserId) .. "SavedAT")
if result ~= nil then
plrdata[tostring(plr.UserId)] = plrstore:GetAsync(tostring(plr.UserId) .. tostring(result))
else
plrdata[tostring(plr.UserId)] = {}
end
while true do wait(60)
plrstore:SetAsync(tostring(plr.UserId), plrdata[tostring(plr.UserId)])
plrstore:SetAsync(tostring(plr.UserId) .. "SavedAT", ver)
end
end)
plrs.PlayerRemoving:Connect(function(plr)
plrstore:SetAsync(tostring(plr.UserId), plrdata[tostring(plr.UserId)])
plrstore:SetAsync(tostring(plr.UserId) .. "SavedAT", ver)
end)
local module = {}
function module.Save(plr, key, value)
plrdata[tostring(plr.UserId)][key] = value
end
function module.Get(plr, key, value)
return plrdata[tostring(plr.UserId)][key]
end
function module.WipeData(plr, key)
if key ~= nil then
plrdata[tostring(plr.UserId)][key] = nil
plrstore:SetAsync(tostring(plr.UserId), plrdata[tostring(plr.UserId)])
else
plrstore:SetAsync(tostring(plr.UserId) .. "SavedAT", ver + 1)
end
end