Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I go about allowing access to GUI if they are either on the list or have the gamepass?

Asked by 5 years ago
Edited 5 years ago

Greetings!

I seem to never escape Lua's many confusions, as it's still a steep learning curve for me (but I still hope to really learn it thoroughly and create some great games with my friend), but something new's creeped up on me.

Recently, we had some contributors help with models for this game, and my friend instructed me to script it so that they can access a VIP GUI without having to purchase the pass, as a thank you to them.

So, me, thinking that it's simple, write this (as an example):

local player = game.Players.LocalPlayer
local vipframe = script.Parent.Parent.VIPFrame

function onClick()
    if player.Name == "Jeff" or player.Name == "Bob" or player.Name == "Jeb" then
        print('Player is on list.')
        vipframe.Visible = true
    end
    if game.Workspace.VIPGamepass:InvokeServer(12345678) then
        print('Player has pass.')
        vipframe.Visible = true
        else
            print('Player doesn't have game pass.')
            game:GetService("MarketplaceService"):PromptPurchase(player,12345678)
        end
    end

The button works if say my name is on the list, as in the console it shows 'Player is on list', however when I remove my name to check for the pass... nothing. It doesn't invoke and check if I have the pass, nor displays the VIP GUI, nor prompt me to purchase. I am quite confused, and I have a suspicion that it has to do with my use of if statements, but I am otherwise lost. Any clues?

0
You never closed the print that says they don't have the pass, properly. crookedsuper 56 — 5y
0
Simple typo, thanks for pointing it out, but still. JosefuAto 4 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Try this, I used a different ROBLOX function to check if they own the pass.

local player = game.Players.LocalPlayer
local vipframe = script.Parent.Parent.VIPFrame

function onClick()
    if player.Name == "Jeff" or player.Name == "Bob" or player.Name == "Jeb" then
        print('Player is on list.')
        vipframe.Visible = true
    end
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.userid,12345678) then
        print('Player has pass.')
        vipframe.Visible = true
        else
            print("Player doesn't have game pass.")
            game:GetService("MarketplaceService"):PromptPurchase(player,12345678)
        end
    end
0
Thank you good sir! It worked! I'm not sure why I was using what I was using before.. maybe I should read up more. But thanks again! JosefuAto 4 — 5y
Ad

Answer this question