Roblox Studio数值问题

在编写Roblox Studio代码时,我遇到了一些问题,下面是一个简单的例子:

local Value = Instance.new("NumberValue")
Value.Value = 10
while true do
   print(Value.Value)
end

到目前为止一切都很正常,但是如果我添加或删除"Value"的值,它仍然会打印10。另外,当我想将值保存到Datastore中时,它只会取"Value"创建时的值。以下是保存玩家数据的代码。

game.Players.PlayerRemoving:Connect(function(player)
    local money = player:WaitForChild("money")
    local DataStoreService = game:GetService("DataStoreService")
    local MoneyStore = DataStoreService:GetDataStore("PlayerMoney")
    local success, errorMessage = pcall(function()
        MoneyStore:SetAsync(player.UserId, money.Value)
    end)
    if not success then
        print(errorMessage)
    end
    print("保存了 "..player.Name.." 的金额!它是 $"..money.Value)
end)

原文链接 https://stackoverflow.com/questions/69233974

点赞
stackoverflow用户16938675
stackoverflow用户16938675

我不理解你的问题,但我认为你正在使用 LocalScript,请使用服务器脚本来进行更改。如果需要玩家,那么有一些参数可以给出触碰、触发、添加或移除动作的玩家。如果你正在使用 UserInputService,那么你应该使用 RemoteEvent 或 RemoteFunction。

2021-09-22 04:32:53