Help with gamepass shop

local GamepassOne = script.Parent:WaitForChild("GamepassOne")
local GamepassTwo = script.Parent:WaitForChild("GamepassTwo")
local GamepassThree = script.Parent:WaitForChild("GamepassThree")
local GamepassFour = script.Parent:WaitForChild("GamepassFour")

local MarketplaceService = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer
local Players = game:GetService("Players")

local GamepassOneId = 133718605

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if MarketplaceService:UserOwnsGamePassAsync(plr.UserId,GamepassOneId) then
			print("Hello")
		end
	end)
end)

GamepassOne.Buy.MouseButton1Click:Connect(function()
	
	local hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassOneId)
	
	if hasPass then
		print("User ownes this gamepass already.")
	else
		MarketplaceService:PromptGamePassPurchase(Player, GamepassOneId)
	end
end)

This script isn’t checking if the player owns the gamepass / does not change the button to visible and the other to invisible.

Try…

local GamepassOne = script.Parent:WaitForChild("GamepassOne")
local GamepassTwo = script.Parent:WaitForChild("GamepassTwo")
local GamepassThree = script.Parent:WaitForChild("GamepassThree")
local GamepassFour = script.Parent:WaitForChild("GamepassFour")

local MarketplaceService = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer
local Players = game:GetService("Players")

local GamepassOneId = 133718605

Players.PlayerAdded:Connect(function(plr)
	repeat task.wait()until game.workspace:FindFirstChild(plr.Name)
		if MarketplaceService:UserOwnsGamePassAsync(plr.UserId,GamepassOneId) then
			print("Hello")
		end
	
end)

GamepassOne.Buy.MouseButton1Click:Connect(function()
	
	local hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassOneId)
	
	if hasPass then
		print("User ownes this gamepass already.")
	else
		MarketplaceService:PromptGamePassPurchase(Player, GamepassOneId)
	end
end)

Same result as mine. Not to sure what the deal is

Can I see how the explorer is set up with the guis?

image


Here you go

I am trying some print’s tell me what is said in the output

local GamepassOne = script.Parent:WaitForChild("GamepassOne")
local GamepassTwo = script.Parent:WaitForChild("GamepassTwo")
local GamepassThree = script.Parent:WaitForChild("GamepassThree")
local GamepassFour = script.Parent:WaitForChild("GamepassFour")

local MarketplaceService = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer
local Players = game:GetService("Players")

local GamepassOneId = 133718605

print("Loading script...")
	repeat task.wait()until game.workspace:FindFirstChild(Player.Name)
		if MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamepassOneId) then
GamepassOne.Owned.Visible = true
GamepassOne.Buy.Visible = false
GamepassOne.Buy.Active = false


			print("Own's Gamepass")
		end

GamepassOne.Buy.MouseButton1Click:Connect(function()
	
	local hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassOneId)
	print("Checking Ownership")
	if hasPass == true then
		print("User ownes this gamepass already.")
GamepassOne.Owned.Visible = true
GamepassOne.Buy.Visible = false
GamepassOne.Buy.Active = false
	else
print("Sending prompt.")
		MarketplaceService:PromptGamePassPurchase(Player, GamepassOneId)
print("prompt sent")
	end
end)

(Added a fix, try again if error is with plr)

Button NOT Clicked

Button CLICKED

Everything seems to be fine except the owned gamepass showing instead of buy

It looks like everything runs as it should?

Yes, but there is the buy button which you see now, then their is a owned button which is invisible since its an image. The owned button doesnt show up even though I own the gamepass

Ah. Let me script that in. One second

image

Try this script now with it being updated

Sweet it worked thank you for your help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.