♚︎ Of Nothing
Мыслитель
(5491)
2 месяца назад
Вот исправленный код:
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MainData")
Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder", player)
folder.Name = "leaderstats"
local CoinsValue = Instance.new("IntValue", folder)
CoinsValue.Name = "BoCoins"
local success, data = pcall(function()
return DataStore:GetAsync(player.UserId)
end)
if success and data then
CoinsValue.Value = data["BoCoins"]
else
CoinsValue.Value = 50
end
end)
Players.PlayerRemoving:Connect(function(player)
local success, res = pcall(function()
return DataStore:SetAsync(player.UserId, {
BoCoins = player.leaderstats.BoCoins.Value
})
end)
if not success then
warn("Данные не были сохранены:", res)
end
end)
local Player = game:GetService("Players")
local DatastoreService = game:GetService("DataStoreService")
local DataStore = DatastoreService:GetDataStore("MainData")
Player.PlayerAdded:Connect(function(player)
local folder = Instance.new ("Folder",player)
folder.Name = "leaderstats"
local CoinsValue = Instance.new ("IntValue",folder)
CoinsValue.Name = "BoCoins"
local data = DataStore:GetAsync(Player.UserId) -- nil
if data ~= nil then
CoinsValue.Value = data ["BoCoins"]
else
CoinsValue.Value = 50
end
end)
Player.PlayerRemoving:Connect(function(player)
local success, res = pcall(function()
DataStore:SetAsync(player.UserId,{
Coins = Player.leaderstats.BoCoins.Value
})
end)
if not success then
warn("Данные не были сохранены:",res)
end
end)