BindableFunction question with notifications

I want to use the Notifications to prompt players to buy a gamepass, however atm it prompts them to buy the pass before they even click a button

local function BuyGamepass(id)
	MarketplaceService:PromptGamePassPurchase(Player, id)
end

StarterGui:SetCore('SendNotification',
		{
			Title = GamepassInfo.Name,
			Text = GamepassInfo.Description,
			Image = 'rbxassetid://' .. GamepassInfo.IconImageAssetId,
			Duration = 5,
			Callback = BuyGamepass(GamepassId),
			Button1 = 'Buy',
			Button2 = 'Cancel'
		}
	)

The hud says

Callback BindableFunction Optional A BindableFunction that should be invoked with the text of the button pressed by the player.

I’m not entirely sure what that means, how I can get my current setup to work when they click ‘Buy’

1 Like

You need to have a local script that checks for when the button is clicked. Then you :InvokeServer() with the BindableFunction on the local script, which will then prompt the player to purchase. I’m not sure why you are using Roblox’s SendNotification, but I recommend you use UI instead of Roblox. If you do want to use SendNotification, you need a way to activate it.

1 Like

I’m using the SendNotification for a reason. I don’t want to create my own, when Roblox provides a perfect system already

Are you trying to have it automatically ask the user to buy the gamepass?

I just want a notification to appear asking if they want to buy. I don’t want the gamepass prompt to just appear in the middle of their screen unless they click buy

1 Like

Then you want to do a while loop for time to ask the user

while wait(60) do
--SendNotification
end

Then you just check for when they press Buy, and then do your BuyGamepass function
I’m not sure how Roblox’s SendNotification works, so you should look it up

1 Like

That’s the problem, there isn’t much information on how to use them properly

1 Like

The Callback takes a BindableFunction as a parameter. In your code here, you are passing the return value of the function (in this case, nil). You have to create a BindableFunction (including setting the OnInvoke function) and pass the entire object as the callback parameter.

Unfortunately, the only parameter passed is the text of the button that is pressed. You’ll need to know the gamepass ID ahead of time (ie. setting it as a global variable or some other way to keep track of it).

local bindf = Instance.new("BindableFunction")
bindf.OnInvoke = function(buttonText)
    ...
end

-- In your SendNotification table
{
    ...
    Callback = bindf
    ...
}

Keep in mind that the OnInvoke function will also call for the Cancel button, which means you need to make sure you’re properly checking which button is pressed.

1 Like