In summary, I’m trying to return a boolean if player owns AT LEAST ONE gamepass from table but it’s always returning false regardless.
local __PASSES = {
123456,
1234567,
12345678
}
function CheckIfOwnsPassThenReturnBoolean(Player: Player?): boolean?
for _,v in ipairs(__PASSES) do -- __PASSES IS A TABLE OF IDS. (EX: 123458789)
if __MRKSERVICE:UserOwnsGamePassAsync(Player.UserId, __PASSES) then
return true
else
return false
end
end
end
---
if CheckIfOwnsPassThenReturnBoolean(__PLR) then
__PLR:FindFirstChild("leaderstats"):WaitForChild("TIX").Value -= __TOOLS[__ITEMNAME] / 2
else
__PLR:FindFirstChild("leaderstats"):WaitForChild("TIX").Value -= __TOOLS[__ITEMNAME]
end
The code above is the issue, if the first gamepass you loop through is not valid it returns false.
Instead put the following code after the for loop:
return false
Now the code would look something like this:
function CheckIfOwnsPassThenReturnBoolean(Player: Player?): boolean?
for _,v in ipairs(__PASSES) do -- __PASSES IS A TABLE OF IDS. (EX: 123458789)
if __MRKSERVICE:UserOwnsGamePassAsync(Player.UserId, __PASSES) then
return true -- if one value is true then return true
end
end
return false -- if none of the ones we have looped through are true then we return false
end
Another thing that you probably didn’t notice, but return also BREAKS all loops within a function, so your CheckIfOwnsPassThenReturnBoolean function is only running once in this scenario here
Also, here’s a little trick to keep in mind Turn your UserOwnsGamePassAsync() function into a variable since it returns back a Bool, so you don’t have to return 2 values through an else statement:
local __PASSES = {
123456,
1234567,
12345678
}
local function CheckIfOwnsPassThenReturnBoolean(Player: Player?): boolean?
for _,v in ipairs(__PASSES) do -- __PASSES IS A TABLE OF IDS. (EX: 123458789)
local BadgeCheck = __MRKSERVICE:UserOwnsGamePassAsync(Player.UserId, v)
if BadgeCheck == true then
return BadgeCheck
else
warn(Player.Name.." does not have the "..v.." Gamepass!")
end
end
end
---
if CheckIfOwnsPassThenReturnBoolean(__PLR) then
__PLR:FindFirstChild("leaderstats"):WaitForChild("TIX").Value -= __TOOLS[__ITEMNAME] / 2
else
__PLR:FindFirstChild("leaderstats"):WaitForChild("TIX").Value -= __TOOLS[__ITEMNAME]
end