Gamepass purchase not working

Hello, I am trying to fix an issue where the player buys a gamepass, and if purchased, a remote event is sent from the client to the server, however I get this error when trying to reference the player.


local plr = Players.LocalPlayer

few lines later…

event:FireServer(gamePassID, plr)


hasPass = gs:UserOwnsGamePassAsync(plr.UserId, id)

And I am getting the following error.

  13:20:05.268  Error while checking if player has pass: ServerScriptService.RobuxShopHandler:8: attempt to index number with 'UserId'  -  Server - RobuxShopHandler:12

I have not found a solution so far, so I am asking here.

Firing to the server automatically gives the player instance who fired the event as the first parameter, how does your Onserverevent look like?

Here is what it looks like.
event.OnServerEvent:Connect(function(id, plr)

local hasPass = false

local success, message = pcall(function()
	hasPass = gs:UserOwnsGamePassAsync(plr.UserId, id)

if not success then
	warn("Error while checking if player has pass: " .. tostring(message))

if hasPass then
	if id == 16234236 then --Rainbow Trail
		local trail = plr.Character.HumanoidRootPart:FindFirstChild("Trail")
		if trail then
		local newtrail = game.ServerStorage.Trails.RainbowTrail:Clone()
		newtrail.Parent = plr.Character.HumanoidRootPart
		newtrail.Name = "Trail"
	print("The user "..plr.Name.. " does not have the gamepass with the id "
	-- Player does NOT own the game pass; prompt them to purchase


Change that to


The player instance who fired it is always given first, you also don’t need to give the player yourself as it does that for you, so just fire the id only


First parameter of OnServerEvent is the player always.

Removing the player gave me this.

 Error while checking if player has pass: ServerScriptService.RobuxShopHandler:8: attempt to index nil with 'UserId

Did you also change the onServerEvent so plr is first and id is second? When I mentioned removing the player, I meant that only for the FireServer, as it’s unneeded, you still need plr for the first parameter of OnServerEvent, as that is given automatically

I’m an idiot lol, it seems like the gamepass is registered when the player leaves. Sorry for wasting your time.

1 Like