Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why do I need to add after .Value after I already defined it at the beginning of the script?

Asked by 4 years ago

I had this script that is supposed to check to see if you are below lvl 0, and make you lvl 1, my first script, this:

local lvl = plr.leaderstats.levels.Value
local xp = plr.leaderstats.xp.Value
if lvl <= 0 then
    lvl = 1
end

didn't work, but then I just started messing around to try and get it to work and stumbled upon a working solution, but I have no clue why it works, and the original one doesn't, here's my working code:

local lvl = plr.leaderstats.levels
local xp = plr.leaderstats.xp
if lvl.Value <= 0 then
    lvl.Value = 1
end

Can anybody explain to me why I couldn't define the .Value at the top of the script, and had to define it every time?

1 answer

Log in to vote
0
Answered by 4 years ago

When you set a variable to the value of an IntValue, you are essentially telling it that it is that number. In your first script you are basically setting lvl to whatever number then setting the variable lvl to 1, not the value of levels.

Ad

Answer this question