Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.