Hello everyone my data store keep breaking is this script right can you find the cause for the breaking?
i have tried to change the values local set name and it works still but when I publish a big update from another place to the specified place that places data breaks
local DataStoreService = game:GetService(“DataStoreService”)
local playerData = DataStoreService:GetDataStore(“PlayerData”)
local function onPlayerJoin(player) – Runs when players join
local leaderstats = Instance.new("Folder") --Sets up leaderstats folder
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Wallet = Instance.new("IntValue") --Sets up value for leaderstats
Wallet.Name = "Wallet"
Wallet.Parent = leaderstats
local Bank = Instance.new("IntValue") --Sets up value for leaderstats
Bank.Name = "Bank"
Bank.Parent = leaderstats
local playerUserId = "Player_" .. player.UserId --Gets player ID
local data = playerData:GetAsync(playerUserId) --Checks if player has stored data
if data then
Wallet.Value = data['Wallet']
Bank.Value = data['Bank']
else
-- Data store is working, but no current data for this player
Wallet.Value = 0
Bank.Value = 80000
end
end
local function create_table(player)
local player_stats = {}
for _, stat in pairs(player.leaderstats:GetChildren()) do
player_stats[stat.Name] = stat.Value
end
return player_stats
end
local function onPlayerExit(player) --Runs when players exit
local player_stats = create_table(player)
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player_stats) --Saves player data
end)
if not success then
warn('Could not save data!')
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)