hi!我在使用datastore时,好像发现储存和读取没什么用.
储存脚本:
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("Points")
local function Save(player)
local SaveTable = {
player.leaderstats.Points.Value
}
local success, err = pcall(function()
dataStore:SetAsync(player.UserId, SaveTable) -- Save the data with the player UserId, and the table we wanna save
end)
if success then
print("Data has been saved!")
print(SaveTable)
else
print("Data hasn't been saved!")
warn(err)
end
end
game.Players.PlayerRemoving:Connect(function(player) -- When a player leaves the game
Save(player) -- Save the data
end)
game:BindToClose(function() -- When the server shuts down
for _, player in pairs(game.Players:GetPlayers()) do
Save(player) -- Save the data
end
end)
读取腳本
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("Points") --
print("Leaderboard Loader Loaded!")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local points = Instance.new("IntValue", leaderstats)
points.Name = "Points"
local xp = Instance.new("IntValue", leaderstats)
xp.Name = "XP"
local data
local success, err = pcall(function()
data = dataStore:GetAsync(player.UserId)
end)
if success and data then
points.Value = data[1]
else
print("沒數據!")
end
end)
谁能帮帮我吗?我不太知道错在哪