I have been trying this out with group permissions but I can’t seem to get it right. I want to have a group requirement to receive a weapon. You can be in any of the groups, and you will be eligible to get that weapon. I’ve stored the values into a module script. Here’s an example:
-- Module Script
local module = {}
module.Tool1Stats = {
Groups = Group1 or Group2 or Group3
RequiredRank = 0
}
-- Main Script
local module = require(module)
local player = game.Players.LocalPlayer
if player:GetRankInGroup(module.Tool1Stats.Group) > module.Tool1Stats.RequiredRank then
-- give the player tools
end
The problem comes in the if statement. It only checks one of the groups, when I have multiple groups stored, thus if someone isn’t in Group1, but is in group 2 or group 3, they don’t get the weapon even though they should be eligible. How can I solve this?
Do you understand what does the logical or operator do? or is a logical operator that returns the left operand if the left operand is truthy, otherwise it returns the right operand.
I presume that Group1 or Group2 or Group3 evaluates to Group1 because of this.
Ok so, in this case the best way to do this would be to use a for loop to iterate through a list of ranks, it would be repetitive to use many logical operators if you only needed to use one.
for example
local Ranks = {1,2,3,4}
if Ranks[1] > X or Ranks[2] > X or Rank[3] > X or Rank[4] > X then
print("Gets tools")
end
vs
local Ranks = {1,2,3,4}
for _, Rank in next, Ranks do
if Rank > X then
print("Gets Tools")
end
end