Make a part of a gui appear when the player owns a game pass

Make a part of a gui appear when the player owns a game pass.

I’ve tried making it so that a specific part of the GUI is visible when a player owns a gamepass. Ive tried using this script but it wouldn’t work. Please help me out
image

image
The local script is something else that has to do with the button itself but the script is the one i need help with!

Please help, thanks!

Hmm do you mean this part?
image

Is this from a localscript or a normal script?

Its from the normal script, the local script is something else

You can’t change Gui stuff using a normal script, so use a local script.

Hmm, what do you mean by keep on getting the parent to get the gui instance?

Ill try a local script to see if it works!

image
image

I assume the second picture is the Gamepass gui. You can remove the
script.Gui.Visible = false part of the script and go to the gui instance property and uncheck RestetOnSpwan. Also, do you have your output window open to show you any errors?

You could add another event which executes when the player has bought the gamepass in game.

Also a while loop isn’t wise, since you want to aim on reserving resources.

Yeah the second picture is of the gamepass button, but im not sure what you meant by script.Gui.Visible = false since I didn’t write that in the script

Hmm i see what you mean, is it okay if i try to use this script and see if it works?

the problem is you should be doing it in a local script because it is a GUI, but you also want to be checking if the player owns the gamepass from server, so i suggest having a remotefunction, that from the localscript, asks the server if the player owns, and the sever returns true or false (Of course you have to script that)
It would be something like this
Server Script

local RemoteFunction = game.ReplicatedStorage.RemoteFunction
local MPS = game:GetService("MarketplaceService")
local gamepass = 123456

RemoteFunction.OnServerInvoke:Connect(function(plr)
    local Data = MPS:UserOwnsGamePassAsync(plr.UserId,gamepass)
    return Data
end)

And then in your local script you would remove the gamepass check, and include this:

local OwnsGamepass = game.ReplicatedStorage.RemoteFunction:InvokeServer()
if OwnsGamepass == true then
    script.Parent.Visible = true
end

Tried this script but it didn’t work!

did you create a remotefunction in serverstorage?

There’s no need to check if the player owns the Game Pass on the server, this is just to make a GUI visible. Any actions that the player can take using the GUI will need to be validated anyway.

Of course, go ahead and try to get it working!

Wait i messd up i meant to respond to anoyher player

So ive tried but cant get it to work

same script as u sent me but it dosent work!

Sorry, I made a typo in the event name that I didn’t correct in the code I posted. I’ve fixed it now. In the future, check the Output window to see what issues with your scripts are.