game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 1
level.Parent = leaderstats
local xp = Instance.new("IntValue")
xp.Name = "XP"
xp.Value = 0
xp.Parent = player
end)local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerData")GetDataStore("PlayerData")GetDataStore("GameData")game.Players.PlayerAdded:Connect(function(player)
local success, data = pcall(function()
return playerDataStore:GetAsync(player.UserId)
end)
if success and data then
print("Данные игрока загружены")
else
print("Сохранённых данных нет")
end
end)if success and data then
coins.Value = data.Coins or 0
level.Value = data.Level or 1
xp.Value = data.XP or 0
enddata.Coins or 0game.Players.PlayerRemoving:Connect(function(player)
end)local data = {
Coins = player.leaderstats.Coins.Value,
Level = player.leaderstats.Level.Value,
XP = player.XP.Value
}local success, err = pcall(function()
playerDataStore:SetAsync(player.UserId, data)
end)
if success then
print("Данные сохранены")
else
warn("Ошибка сохранения:", err)
endpcall(function()
-- код DataStore
end)local success, err = pcall(function()
playerDataStore:SetAsync(player.UserId, data)
end)
if not success then
warn(err)
endlocal DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local playerDataStore = DataStoreService:GetDataStore("PlayerData")
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 1
level.Parent = leaderstats
local xp = Instance.new("IntValue")
xp.Name = "XP"
xp.Value = 0
xp.Parent = player
local success, data = pcall(function()
return playerDataStore:GetAsync(player.UserId)
end)
if success and data then
coins.Value = data.Coins or 0
level.Value = data.Level or 1
xp.Value = data.XP or 0
end
end)
Players.PlayerRemoving:Connect(function(player)
local data = {
Coins = player.leaderstats.Coins.Value,
Level = player.leaderstats.Level.Value,
XP = player.XP.Value
}
local success, err = pcall(function()
playerDataStore:SetAsync(player.UserId, data)
end)
if success then
print("Данные сохранены для " .. player.Name)
else
warn("Ошибка сохранения:", err)
end
end)Coins = 500
Level = 5
XP = 250local data = {
Coins = 2500,
Level = 15,
XP = 750,
Wins = 12,
CompletedMissions = 8,
Pets = {
"Dog",
"Cat"
}
}