Roblox Studio 价值问题
Roblox Studio Value Issue
我对在 Roblox Studio 中编码时发生过几次的事情有疑问:
我有一个简单的问题示例:
local Value = Instance.new("NumberValue")
Value.Value = 10
while true do
print(Value.Value)
end
到目前为止一切正常,但如果我添加或删除“Value”的值,它仍会打印 10。
当我想将值保存在数据存储中时,情况是一样的,它只采用创建“值”时存在的值。这是我保存播放器数据的代码。
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("saved "..player.Name.."'s money! It is $"..money.Value)
end)
我不明白你的问题,但我认为你使用的是 LocalScript,请使用服务器脚本进行更改。如果想要播放器,则有一些参数可以为您提供触摸、触发、添加或删除的播放器。如果您使用的是 UserInputService,那么您应该使用 RemoteEvent 或 RemoteFunction。
我对在 Roblox Studio 中编码时发生过几次的事情有疑问: 我有一个简单的问题示例:
local Value = Instance.new("NumberValue")
Value.Value = 10
while true do
print(Value.Value)
end
到目前为止一切正常,但如果我添加或删除“Value”的值,它仍会打印 10。 当我想将值保存在数据存储中时,情况是一样的,它只采用创建“值”时存在的值。这是我保存播放器数据的代码。
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("saved "..player.Name.."'s money! It is $"..money.Value)
end)
我不明白你的问题,但我认为你使用的是 LocalScript,请使用服务器脚本进行更改。如果想要播放器,则有一些参数可以为您提供触摸、触发、添加或删除的播放器。如果您使用的是 UserInputService,那么您应该使用 RemoteEvent 或 RemoteFunction。