I've been researching an algorithm for a ds script that is easy to modify for adding or removing values to player statistics. I've recieved a proposition from an (don't leave yet please) AI model that says tables will solve the issue in given manner:
local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerData")
game.Players.PlayerAdded:Connect(function(player)
local data = playerDataStore:GetAsync(player.UserId) or {}
-- Create a folder to store player stats
local statsFolder = Instance.new("Folder")
statsFolder.Name = "PlayerStats"
statsFolder.Parent = player
-- Define default stats
local defaultStats = {
Strength = 0,
Kills = 0,
Coins = 0,
-- Add new stats here as needed
}
-- Load existing data or set defaults
for statName, defaultValue in pairs(defaultStats) do
local statValue = Instance.new("IntValue")
statValue.Name = statName
statValue.Value = data[statName] or defaultValue
statValue.Parent = statsFolder
end
end)
Should I go with this?
-# As in fully explore this idea
