I made a data store script to save multiple values I was wondering if there was any other way to further secure it.
local datastoreservice = game:GetService("DataStoreService")
local playerdata = datastoreservice:GetDataStore("Example")
local function settable(plr)
local newplr_Stats = {}
for _, v in pairs(game.ServerStorage:WaitForChild("ExampleDataStore"):FindFirstChild(plr.Name.."Folder")) do
newplr_Stats[v.Name] = v.Value
end
return newplr_Stats
end
local function Join(plr)
local FolderStore = Instance.new("Folder")
FolderStore.Name = "SAVED"
FolderStore.Parent = game.ServerStorage:WaitForChild("ExampleDataStore")
local gems = Instance.new("IntValue")
gems.Name = "Gems"
gems.Value = 0
gems.Parent = FolderStore
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = FolderStore
-----------------------------------
local KEY = 'Player_'..plr.UserId
local data = playerdata:GetAsync(KEY)
if data then
gems.Value = data['cash']
cash.Value = data['cash']
else
gems.Value = 0
cash.Value = 0
end
end
local function onplayerExit(plr)
local p_stats = settable(plr)
local s, e = pcall(function()
local KEY = 'Player_'..plr.UserId
playerdata:SetAsync(KEY, p_stats)
end)
if not s then
warn("Did Not Save!"..plr.UserId)
end
end