If statement query

Hello everyone,

I was trying to make a chat system and it should be allowed to be used only when you are a certain rank, but in my case I am getting the if statement to return answer true even when the criteria is not met.

As you might be able to see, in the output I have first printed my rank which is 0 and then have given some criteria which if met prints something. Even though it only meets the criteria for BHV, it still prints SLT and MLT.

Am I doing something wrong here?

Your argument’s are basically “incorrect”.

This doesn’t work.
image

You’d have to keep on doing

plr:GetRankInGroup(id) == 63 or lr:GetRankInGroup(id) == 61

Programming doesn’t work like English.
First of all, anything that is not nil and not false will pass a condition check.

if 63 then
    print("63 is not nil and not false!")
end
--> 63 is not nil and not false!

So what you’re essentially doing is this

if (plr:GetRankInGroup(id) == 63) or (65 ~= nil and 65 ~= false) or (68 ~= nil and 68 ~= false) etc

Since 65 ~= nil and 65 ~= false, the condition runs every time.

Again, programming is not english. Do this.

local rank = plr:GetRankInGroup(id)
if rank == 63 or rank == 65 or rank == 68 ...

It looks like you’re just causing a lot of headache for nothing though. Do you actually care about their exact rank, or do you just want them to meet a minimum rank?

local rank = pl:GetRankInGroup(id)
if rank >= 0 then
    BHV.Value = true
end
if rank >= 284 then
    SLT.Value = true
end
if rank >= 63 then
    MLT.Value = true
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.