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 5 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:

1local lvl = plr.leaderstats.levels.Value
2local xp = plr.leaderstats.xp.Value
3if lvl <= 0 then
4    lvl = 1
5end

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:

1local lvl = plr.leaderstats.levels
2local xp = plr.leaderstats.xp
3if lvl.Value <= 0 then
4    lvl.Value = 1
5end

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 5 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