Problem with gamepass script

I want when the gamepass is bought you are then able to click the button and it fires the server however, when i click the button it just tells me that I already own this item and i have not been charged and then it doesnt do anything after here is my script :

local cas = game:GetService("ContextActionService")
local rs = game:GetService("ReplicatedStorage")

local mps = game:GetService("MarketplaceService")
local product = 186581274

local events = rs:WaitForChild("Events")
local BallerEvent = events:WaitForChild("Baller")
local uis = game:GetService("UserInputService")

local button = script.Parent.BallerButton
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local waittime = 10

local BallAnim = animator:LoadAnimation(script:WaitForChild("Animation"))


local debounce = false

local function Baller()
	if debounce == true then
		return
	elseif debounce == false then
		local clone = game.Workspace.Basket:Clone()
		BallerEvent:FireServer(character)
		BallAnim:Play()
		debounce = true
		wait(waittime)
		debounce = false
	end
end

button.MouseButton1Click:Connect(function(plr)
	if mps:PlayerOwnsAsset(game.Players.LocalPlayer,product) == true then
		Baller()
		button.Active = false
		wait(waittime)
		button.Active = true
	else
		mps:PromptGamePassPurchase(game.Players.LocalPlayer,product)
	end
end)

mps.PromptGamePassPurchaseFinished:Connect(function(player, pass_id, was_purchased)
	if product == pass_id and was_purchased then
		game.Workspace.Bought:Play()
	end
end)

help would be appreciated :slight_smile:

Since you already have the gamepass in your account, was_purchased is false. was_purchased only returns true if the gamepass is bought in that prompt, not bought before. If you still want the sound to be played if the player already owns the gamepass:

mps.PromptGamePassPurchaseFinished:Connect(function(player, pass_id, was_purchased)
	if product == pass_id and (was_purchased or --[[check if payer owns gamepass]]) then
		game.Workspace.Bought:Play()
	end
end)

It still gives me the “Error. You already own this item, your account has not been charged” also still doesnt
fire the “Baller Event”

The documentation says to avoid this function when checking because it uses a different ID system and alternatively use

UserOwnsGamePassAsync()

This could be the root cause of your issue

1 Like

Yes that was the issue, it works now thank you

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