0
votes

I am a student and I am trying to get the value of an "IntValue" to use has level, what I mean by this is that I need to have a skill level for each individual player and use this skill level to multiply the amount of damage the skill does.

for example: Skill level is 5

the damage should be: baseDamage * SkillLevel

in my case. base damage is 2 so the end result should be 10 damage.

but when I try doing this whit code it doesn't work. (I'm not the best at LUA and I'm fairly new to stack so I apologize in advance)

Code (So far I got this):

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)

I just showed the relevant pieces of code. everything that was not relevant to this wasn't shown (except for: XP = XP + .5 which is in the code I'm not showing)

hope this helps figure out what the problem is. as said above: "I'm not the best at LUA and I'm fairly new to stack so I apologize in advance"

1

1 Answers

0
votes

In your code, you store SkillLevel.Value into the LevelValue local variable. This takes a snapshot of that value and stores it in the variable. So when you modify the local variable, you are not updating the IntValue object that is storing SkillLevel.

When you want to update SkillLevel, you need to update the IntValue directly :

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