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

My brain can't seem to handle what I'm trying to do?

So, I'm trying to make it so you have an overall experience, and you level up whenever that hits a certain point(that I set for each)

For example:

Rank 1 - hit 0 XP(obviously) Rank 2 -100 XP Rank 3 -250 XP rank 4 - 750 XP

I tried something like this:

if xp.Value <= 0 then
		if xp.Value <=100 then
			--code
		else
			--level 0?
		end
	end

1 comment

0

If you mean what the script is doing is that for LINE 1: Checking if the XP is greater than or equal to 0 so no negative numbers come in-tact, LINE 2: Checking if the XP is greater than 100 which would mean you pass LEVEL 1 i'm guessing, LINE 5: I don't see a point towards the else, unless you want it to do something if it's NOT that amount of XP.

2 answers

I think elseif may be what you’re looking for with something like this:

local rank = 0
if xp.Value < 100 then
	rank = 1
elseif xp.Value < 250 then
	rank = 2
elseif xp.Value < 750 then
	rank = 3
end
print(rank)

1 comment

0

Thanks, I feel like a legitimate idiot, but I appreciate it haha

To make reading conditionals (if statements) and their blocks easier, make sure to properly indent your code. It seems like you might need a bit more practice with conditionals, so if you haven't already, read through this wiki page about conditional statements. In any case, I've indented and commented your code to help understand what you've got. I hope it helps, and doesn't make things more confusing for you:

if xp.Value <= 0 then
    -- "xp.Value is <= 0"

    -- The below conditional is useless because the condition
    --    will always evaluate to true as long as we're in
    --    this code block: this means line 09 will always run
    --    and line 11 will never run.
    if xp.Value <=100 then
        -- "xp.Value is <= 0 and also <= 100"
    else
        -- "xp.Value is <= 0 and is > 100"
    end
    -- "xp.Value is <= 0"
end

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