Module not working

Hi! I was making module scripts for a marketplace system but something isn’t right about it. Here’s my module script:

local Pass = {}

function Pass.Prompt(service, player, ID)
	service:PromptGamePassPurchase(player, ID)
end

function Pass.Owned(service, key, ID)
	service:UserOwnsGamePassAsync(key, ID)
end

return Pass

And here’s my script in the touched part:

local MarketplaceFunction = require(game:GetService("ReplicatedStorage").GamePassHandler)

local mps = game:GetService("MarketplaceService")
local pass = 27341589

script.Parent.Touched:Connect(function(hit)
	
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if player then
		if MarketplaceFunction.Owned(mps, player.UserId, pass) then
			print("Owned!")
		else
			print("Not yet owned!")
			MarketplaceFunction.Prompt(mps, player, pass)
		end
	end
	
end)

The problem is that the output is saying I don’t own the pass AND when prompt at the same time, it says I already own the item. Please help me fix this.

1 Like

You don’t return anything from your module, yet you are using it in a if-statement.

2 Likes

may I ask why not just use those functions directly instead of calling them from a module?

local mps = game:GetService("MarketplaceService")
local pass = 27341589

script.Parent.Touched:Connect(function(hit)
	
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if player then
		if mps:UserOwnsGamePassAsync(player.UserId,pass) then
			print("Owned!")
		else
			print("Not yet owned!")
			mps:PromptGamePassPurchase(player,pass)
		end
	end
end)

but if you’re insisted to continue with this, then try -

local Pass = {}

function Pass.Prompt(service, player, ID)
	service:PromptGamePassPurchase(player, ID)
	return false
end

function Pass.Owned(service, key, ID)
	service:UserOwnsGamePassAsync(key, ID)
	return true
end

return Pass
1 Like

Thanks for your help! By the way, I’m just learning about module scripts so I thought I could try test them myself.

Shouldn’t this return the result of the function? This will currently indicate that all user own all passes.