I’m currently working on a rank management center. I want to make it so when you click the button to redeem your rank, it’ll come up with “Success” if the player owns any of the multiple gamepasses or “Error” if they own none.
Essentially, my script is only checking the first gamepass and not the other listed gamepasses.
My Code:
local MPS = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
script.Parent.ClaimRank.MouseButton1Click:Connect(function()
game.ReplicatedStorage.ClaimRank:FireServer()
if MPS:UserOwnsGamePassAsync(player.UserId, 19494628 or 19494690 or 19494753 or 19494800 or 19496628 or 22512865 or 22512881 or 22512892 or 22512900 or 22512923 or 2022579) then
script.Parent.ClaimRank.Text = "Successfully Claimed!"
wait(1)
script.Parent.ClaimRank.Text = "Claim Rank"
else
script.Parent.ClaimRank.Text = "You don't own a gamepass!"
wait(1)
script.Parent.ClaimRank.Text = "Claim Rank"
end
end)
How can I make the script look through all the listed gamepasses and give the appropriate response in the TextLabel? Any help is appreciated.
local passes = {
["Officier"] = 19274629, --// Gamepass ID
["Head Security"] = 2888273,
["Janitor"] = 2252667,
}
Then, do a loop of the passes table.
for _, gamepass in pairs(passes) do
for _, button in pairs(buttons) do --// Your button variable in table
If button.Name == gamepass then
--// Give them the rank or do something.
end
end
end
local MPS = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local gamepassIds = {19494628, 19494690, 19494753, 19494800, 19496628, 22512865, 22512881, 22512892, 22512900, 22512923, 2022579}
script.Parent.ClaimRank.MouseButton1Click:Connect(function()
game.ReplicatedStorage.ClaimRank:FireServer()
for _, v in ipairs(gamepassIds) do
if MPS:UserOwnsGamePassAsync(player.UserId, v) then
script.Parent.ClaimRank.Text = "Successfully Claimed!"
wait(1)
script.Parent.ClaimRank.Text = "Claim Rank"
break
end
end
script.Parent.ClaimRank.Text = "You don't own a gamepass!"
wait(1)
script.Parent.ClaimRank.Text = "Claim Rank"
end)
Here I’ve created an array of gamepass ID’s and then used a generic for loop to traverse over each ID. If it is found that one of the gamepasses is owned by the user then a break statement is executed to stop the loop (as we no longer need to check if the user owns any of the remaining gamepasses). If on the other hand the user is found to own none of the gamepasses the code outside of the generic for loop is executed (the last 3 lines of code before the final end statement).