Gamepass not working

Hi guys, i have made this script for my gamepass but if the player does’nt have gamepass, the windows for prompt gamepass not showing… it’s a script not localscript:

		local id = 8535327
		local MarketplaceService = game:GetService("MarketplaceService")
		if MarketplaceService:UserOwnsGamePassAsync(plr.UserId,id) then
			plr.PlayerGui.Teleporter.Frame.Visible = true
			plr.PlayerGui.Teleporter.Framed.Visible = true
		else
			game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, id)
		end

it’s not all code, just the part of my gamepass, if palyer have gamepass the Frame is visible it’s working good, but if the player don’t have gamepass i don’t have the prompt window

Only when the player press the key “E”

try putting prints to make sure it works and gets to the correct areas. I don’t see anything wrong with this yet.

May we see the entire script? This part of the script seems fine.

The print is’nt fire i got this error: Unable to cast Value to object

traveler.OnServerEvent:Connect(function(plr, tool)
	local mag = (tool:WaitForChild("Handle").Position - plr.Character.PrimaryPart.Position).magnitude
	
	if mag < 10 then
		local id = 8535327
		local MarketplaceService = game:GetService("MarketplaceService")
		if MarketplaceService:UserOwnsGamePassAsync(plr.UserId,id) then
			plr.PlayerGui.Teleporter.Frame.Visible = true
			plr.PlayerGui.Teleporter.Framed.Visible = true
		else
			print("test")
			game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, id)
		end
	end
end)

try putting a print before the mag < 10 and after the mag < 10 to make sure its that that’s erroring

the print before mag is fire it’s good ^^ juste the line:

game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, id)

don’t working i don’t know why, it’s not a line for localscript only ?

you are sure its getting to that? I don’t see any problem with it.

I don’t know why this is not work… the window for prompt the gamepass not showing :confused:

show me the prints you put in and make sure it did print them all

The print is fire it’s good, i just got this error in this line:

game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, id)

error: unable to cast Value to object

I don’t think that would cause an error like that

Is it the correct ID? It isn’t a product ID to make sure?

I have solved my problem, i have replace the line else by elseif not gamepass… and it’s working !

But i have another problem xd if player has gamepass the frame show correctly, but just one times, if i press “E” the frame will not be visible in second time… :confused:

make sure its firing correctly every time you click E

Yes it’s firing x11 but the frame being visible just the first time i press “E” :thinking:

Are you making this frame visible / invisible with a localscript or a serverscript?

serverscript and its working just one time