Hello I have a data store script and I want feedback and ways to make it more secure, and for it to load faster(The main problem). Currently, It takes about a second for the data to update on the StringValue, and the problem with this is it doesn’t load fast enough when the player spawns so sometimes this can mess up some of my scripts especially when giving items on spawn.
As For the secure part, I am pretty sure this isn’t secure. I would like some feedback to make this more secure and to stop exploiters unable to directly change these values.
local DSS = game:GetService("DataStoreService")
local PlayerData = DSS:GetDataStore("WData001")
local RunService = game:GetService("RunService")
game.Players.PlayerAdded:Connect(function(Plr)
local WDATA = Instance.new("Folder")
WDATA.Parent = Plr
WDATA.Name = "WDATA"
local Weapon = Instance.new("StringValue")
Weapon.Parent = WDATA
Weapon.Name = "Weapon"
Weapon.Value = "None"
local PlrUserId = "Player_"..Plr.UserId
local StoreData = PlayerData:GetAsync(PlrUserId)
if StoreData then
Weapon.Value = StoreData['Weapon']
end
end)
-----------------------------------------------------------------------------------------
local function CreateTable(Plr)
local Plrstats = {}
for _,V in pairs(Plr.WDATA:GetChildren()) do
Plrstats[V.Name] = V.Value
end
return Plrstats
end
local function Save(Plr)
local Plrstats = CreateTable(Plr)
local Sucess, Error = pcall(function()
local PlrUserID = "Player_"..Plr.UserId
PlayerData:SetAsync(PlrUserID, Plrstats)
end)
if not Sucess then
warn("Not Able To Save")
end
end
-----------------------------------------------------------------------------------------
game.Players.PlayerRemoving:Connect(function(Plr)
Save(Plr)
end)
game:BindToClose(function()
for _,Player in pairs(game.Players:GetPlayers()) do
Save(Player)
end
end)