【发布时间】:2021-12-06 19:39:45
【问题描述】:
所以对于初学者来说,我有
playerStats(模块脚本)game.StarterPlayer.StarterCharacterScripts
local module = {}
module.hunger = 0
module.thirst = 100
return module
为了不让你开始失去健康饥饿或口渴必须高于 0。现在我将它设为零,这样我就可以测试我制作的食物,它假设会增加 20 饥饿。这确实有效并阻止了健康损失,但它不会更新 foodBar UI。 (我还没有任何渴求的东西)。
我用于更新屏幕和食物的脚本是:
食品(服务器端)工作区.Food.ClickDetector
local food = script.Parent.Parent
local PlayerStats = require(game.StarterPlayer.StarterCharacterScripts.playerStats)
local gain = 2
local playerFunctions = require(game.StarterPlayer.StarterCharacterScripts.playerFunctions)
script.Parent.MouseClick:Connect(function()
food:remove()
PlayerStats.hunger+=gain
print("Food on click : " .. PlayerStats.hunger)
playerFunctions.updateFood()
end)
更新 foodBar(模块脚本)game.StarterPlayer.StarterCharacterScripts
local module = {}
module.updateFood = function()
local gui = game.StarterGui.ScreenGui
local PlayerStats = require(game.StarterPlayer.StarterCharacterScripts.playerStats)
gui.foodBar.Text = "Hunger: " .. PlayerStats.hunger
end
return module
我不认为它是更新食物栏的功能,因为它在我用于检查玩家统计信息的其他脚本中一开始就起作用
local data = require(game.StarterPlayer.StarterCharacterScripts.playerStats)
local player = script.Parent
local humanoid = player:WaitForChild("Humanoid");
local playerFunctions = require(script.Parent.playerFunctions)
task.spawn(function()
while data.hunger <= 0 or data.thirst <= 0 do
wait(0.1)
humanoid.Health-=1
end
end)
humanoid.Died:Connect(function()
data.hunger = 100
data.thirst = 100
end)
while true do
wait(0.1)
playerFunctions.updateFood()
end
是的,我知道我在这里放了很多代码,但我对 Lua 很陌生,不知道这可能是什么,所以我想确保你能看到所有内容,以防万一发生意外。
【问题讨论】: