Why PromptGamePassPurchase is now working?

I tested gamepass on local server, but its not working. game pass will give tycoon player 2 times more money. whenever i tested it myself, it works because i own the gamepass, but whenever i tried on local server its broken, thus purchase is failing.

can anyone help me out?

buying script (not local script)

local id = 214145059
local players = game:GetService("Players")

script.Parent.ButtonPart.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local player = players:GetPlayerFromCharacter(part.Parent)
		game:GetService("MarketplaceService"):PromptGamePassPurchase(player, id)	
	end
end)

conveyer selling part code

local tycoon = script.Parent.Parent.Parent.Parent
local id1 = 214145059
local marketplace = game:GetService("MarketplaceService")

function func()
	local success, result = pcall(function()
		return marketplace:UserOwnsGamePassAsync(tycoon:GetAttribute("UserID"), id1)
	end)
	
	if success and result then
		return true
	else
		return false
	end
end
script.Parent.Touched:Connect(function(Hit)
	if Hit.Name == "Part" and Hit:FindFirstChild("CashValue") then
		local value =  Hit:FindFirstChild("CashValue").Value
		Hit:Destroy()
		
		
		if func() then
			value = 2 * value
		end
		tycoon:SetAttribute("CollectedCash", tycoon:GetAttribute("CollectedCash") + value)
	end
end)
2 Likes

Whenever prompting purchase, you always want to utilize player.UserId. That identifier never changes, and is the one used for Prompting. Additionally what does the function return? Could you add a print statement for that?

1 Like

idk why but button doesnt work not for no reason?

1 Like

put more prints to understand where is the issue

1 Like

sorry for late reply, it outputs false

1 Like

I’m assuming the UserID is a representation of the players’ UserID? The attribute is a Number, not string correct?

You could either invoke the Server checking if they own it or try it this way with your current implementation.

local Player = game:GetService("Players"):GetPlayerByUserId(tycoon:GetAttribute("UserID"))

local success, result = pcall(function()
	return marketplace:UserOwnsGamePassAsync(Player.UserId, id1)
end)