Issue with seeing if someone has a gamepass

Hello,

So I am trying to script it so that when you click a UI it will say in the console u own the gamepass. For some reason my script is not working but I don’t know why as it says the exact same then the doc on roblox developer hub. (I know I don’t need the Marketplace Service but I am going to make it later so that if u do not have it it will prompt u)

local button = script.Parent

local marketplace = game:GetService("MarketplaceService")

local gamepassplace = game:GetService("GamePassService")

button.MouseButton1Click:Connect(function(plr)

local hasgamepass = gamepassplace:PlayerHasPass(plr, 12226664)

if hasgamepass then

print("Yay u have the gamepass!")

else

print("WHYYYY U DO NOT HAVE THE GAMEPASS!")

end

end)

The player is not passed through the connection as a parameter. Try plr = Game.Players.LocalPlayer before defining hasgamepass.

Still getting the exact same error.
image

Is this a localscript or serverscript

image
Server Script

Yea it’s server script. Why should it be local?

Game.Players.LocalPlayer is for localScript only

Sorry I am quite new to scripting

I would recommend switching to localscript because I don’t think you really have a way of getting the player if the script isnt individual to every player

Just copy and paste the code you have right now into a localscript where the server script is then delete the server script

The only esy way is with PlayerAdded and after save the gamepass the user having on the server side

I mean getting the player who clicked the button because none of the gui click events pass a player parameter iirc

RemoteEvent Client>Server ?
(never trust the client so add security)

Yes but this is from a server script in the first place

Wait so were would you locate this script now?

Where the server script was located but make sure the gui is in a spot where localscripts are ran, playergui (put in startergui), playerscripts, character

It comes up with a warning message saying that the gamepass does not exist?? I copied the ID from the top URL. That is correct right?

Scratch that, (I haver never worked with gamepasses so didn’t know this) replace playerhaspass with UserOwnsGamePassAsync

What is the point of this then?

Because old gamepasses use an old system for asset ids