I'm always looking to learn and stuff like that, can any of you tell me how I could better this DataStore? and tell explain why? thanks
local player = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local DS = game:GetService("DataStoreService")
local data = {
["Data1"] = DS:GetDataStore("Data1"),
}
player.PlayerAdded:connect(function(plr)
local success, err = pcall(function()
local userID = plr.userId
local Stats = Instance.new("Folder")
Stats.Name = "Stats"
local Data1 = Instance.new("IntValue")
Data1.Name = "Data1"
Data1.Value = data["Data1"]:GetAsync(userID)or 1
Stats.Parent = plr
Data1.Parent = Stats
end)
if success then print("Stats in game!")
end
end)
player.PlayerRemoving:connect(function(plr)
local userId = plr.userId
local Stats = plr:WaitForChild("Stats")
data["Data1"]:SetAsync(userId, Stats.Data1.Value)
end)
