1
有沒有理由爲什麼這些不起作用?在RLua儲存玩家數據
球員加盟腳本:
local DataStore = game:GetService("DataStoreService"):GetDataStore("GeneralStats")
game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local points = Instance.new("IntValue", stats)
points.Name = "Points"
local credits = Instance.new("IntValue", stats)
credits.Name = "Credits"
local key = "player-"..player.userId
local savedValues = DataStore:GetAsync(key)
if savedValues then
--Save format: (points, credits)
points.Value = savedValues[1]
credits.Value = savedValues[2]
else
local ValuesToSave = {points.Value, credits.Value}
DataStore:SetAsync(key, ValuesToSave)
end
end)
而當玩家離開這個其他腳本。
local DataStore = game:GetService("DataStoreService"):GetDataStore("GeneralStats")
game.Players.PlayerRemoving:connect(function(player)
local key = "player-"..player.userId
--Save key: {points, credits}
local valuesToSave = {player.leaderstats.Points.Values, player.leaderstats.Credits.Values}
DataStore:SetAsync(key, valuesToSave)
end)
這是一個遊戲我工作,證明(RLua
是Roblox Lua
,如果你不知道)。
你會分享你期望的代碼和它做什麼嗎? – Piglet
試圖澄清。正確的語法 – LoicTheAztec