获取 "IntValue" 的值总是得到默认值

Getting the value of an "IntValue" always gets default value

我是一名学生,我正在尝试获取“IntValue”的值以使用 has level,我的意思是我需要为每个玩家提供一个技能级别并使用该技能级别乘以技能造成的伤害。

例如:技能等级为5

伤害应该是:baseDamage * SkillLevel

就我而言。基础伤害是 2,所以最终结果应该是 10 伤害。

但是当我尝试执行此白色代码时它不起作用。 (我在 LUA 方面不是最好的,而且我对堆栈还很陌生,所以我提前道歉)

代码(到目前为止我得到了这个):

local XP = 0 --Exp Amount
local LevelValue = player.Backpack.ScriptStorage.Player.SkillLevel.Value --Gets the value of the skill level from the "IntValue"


--Other code that I don't want to show (it just checks if a remote event has fired the server, and it adds .5 to the XP every time it fires)



--This is the line that should add 1 to the level
LevelValue = LevelValue + 1
--But everytime it gets to 2 it simply gets set back to 1 (the default level)

我只是展示了相关的代码片段。与此无关的所有内容均未显示(除了:XP = XP + .5 在我未显示的代码中)

希望这有助于找出问题所在。如上所述:“我在 LUA 方面不是最好的,而且我对堆栈还很陌生,所以我提前道歉”

在您的代码中,您将 SkillLevel.Value 存储到 LevelValue 局部变量中。这会拍摄该值的快照并将其存储在变量中。因此,当您修改局部变量时,您并没有更新存储 SkillLevel 的 IntValue 对象。

当你想更新SkillLevel时,你需要直接更新IntValue :

local SkillLevel = player.Backpack.ScriptStorage.Player.SkillLevel
local LevelValue = SkillLevel.Value

-- .. do some other stuff

-- add 1 to the level
SkillLevel.Value = SkillLevel.Value + 1