【发布时间】:2021-02-02 22:58:45
【问题描述】:
代码:
local DataStoreService = game:GetService("DataStoreService")
local InvDataStore = DataStoreService:GetDataStore("InvDataStore")
game.Players.PlayerAdded:Connect(function(player)
local Id = player.UserId
local Inventory = Instance.new("Folder")
Inventory.Name = "Inventory"
Inventory.Parent = player
local Inv = InvDataStore:GetAsync(Id)
print(Inv)
print(table.concat(Inv, " "))
end)
game.Players.PlayerRemoving:Connect(function(player)
local Id = player.UserId
local InvTable = {}
for i, v in pairs(game.Players:FindFirstChild(player.Name).Inventory:GetChildren()) do
print("Repear")
if v:IsA("NumberValue") then
table.insert(InvTable, v)
print(v)
end
end
print(InvTable)
print(table.concat(InvTable, " "))
InvDataStore:SetAsync(Id, InvTable)
end)
输出:
13:25:35.288 - 未命名游戏自动恢复文件已创建 Realism Mod 目前正在运行 v2.09! (x2) 表:0x08cb53598b2d3aa1
表:0xd8ce847b521d4091 1 13:26:26.703 - 从 ::ffff:127.0.0.1|60556 断开连接
探索者:
似乎跳过了这个循环:
for i, v in pairs(game.Players:FindFirstChild(player.Name).Inventory:GetChildren()) do
print("Repear")
if v:IsA("NumberValue") then
table.insert(InvTable, v)
print(v)
end
end
因为它似乎不打印 repear (repeat) OR v (Value) 有人知道怎么回事吗?
注意:我不明白的是,它在保存之后和保存之前不打印值,并且忘记了 for 循环。我可以提供额外的东西。
【问题讨论】:
-
不相关,但是如果将
game.Players:FindFirstChild(player.Name)替换为player会怎样? -
什么都没改变 ilmao,我之前做过,但谢谢你的建议!
标签: for-loop debugging lua roblox