Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Do I Make A Notification That Prompts GamePasses?

I am very clueless about why this is not prompting me I read the [(https://developer.roblox.com/en-us/api-reference/function/StarterGui/SetCore)] I can't still figure it out any help?

Edit: I always get this error message 12:56:45.791 - Unable to cast Function to int64

local MPS = game:GetService("MarketplaceService")
local InfiniteGamePass = 9894874
local Cash2xGamePass = 9914589
local NotificationBindable = Instance.new("BindableFunction")


while wait(7) do
	Purchase = math.random(1,2)
	if Purchase == 1 then
		local function InfiniteGamePass(Text)
			if Text == "Buy" then
				print("Clicked")
				MPS:PromptGamePassPurchase(game.Players.LocalPlayer, InfiniteGamePass)
			elseif Text == "Cancel" then
				print("Cancel")
			end
		end
		NotificationBindable.OnInvoke = InfiniteGamePass
		game.StarterGui:SetCore("SendNotification",  {
			Title = "Infinite Gamepass";
			Text = "Want Infinite Amounts Of Cash?";
			Icon = "";
			Duration = 7;
			Callback = NotificationBindable;
			Button1 = "Buy";
			Button2 = "Cancel";
		})	
	elseif Purchase == 2 then
		local function Cash2x(Text)
			if Text == "Buy" then
				MPS:PromptGamePassPurchase(game.Players.LocalPlayer, Cash2xGamePass)
			elseif Text == "Cancel" then
				print("Cancel")
			end
		end
		NotificationBindable.OnInvoke = Cash2x
		game.StarterGui:SetCore("SendNotification",  {
			Title = "2xCash Gamepass";
			Text = "Want To Double Up Your Earnings?";
			Icon = "";
			Duration = 7;
			Callback = NotificationBindable;
			Button1 = "Buy";
			Button2 = "Cancel";
		})
	end 
end

1 answer

✓ Accepted answer

Hey, gamingwithjbthepro!

I'm going to be attempting to fix the problem that you're having. I apologize that nobody hasn't helped you yet; most people may be busy and unable to help. Anyway, enough talking, let's get into the coding.

The only problem that I can notice, by reviewing your code, is that you didn't do the function correctly for the callback. No worries, you did everything else correctly! I will give you a Local Script that belongs in StarterPlayerScripts, and hopefully, this script can help you add more id's, if needed, and be much easier for you in general.

In the script, you'll see a table that is named "gamepasses." In this table, you'll see more tables that contain an id, title, and desc index. The id should be set to the gamepass id, the title should be set to the title of the notification, and the desc should be set to the notification text. You can add more tables by copying one of the two and just pasting it in and editing it to your needs.

That is the only thing that really needs to be covered since everything else is basically the same. If you have any questions, feel free to reply, and I'll answer them when I get the chance!

See ya around!

--[[
	Local Script in StarterPlayerScripts
]]

-- services --
local players = game:GetService("Players")
local startergui = game:GetService("StarterGui")
local marketplace = game:GetService("MarketplaceService")
local replicatedstorage = game:GetService("ReplicatedStorage")

-- locals --
local client = players.LocalPlayer
local bindableevent = Instance.new("BindableFunction")

local gamepasses = {
	{
		id = 9894874,
		title = "Infinite Gamepass",
		desc = "Want Infinite Amounts Of Cash?"
	},
	
	{
		id = 9914589,
		title = "2xCash Gamepass",
		desc = "Want To Double Up Your Earnings?"
	},
	
}

while wait(7) do
	local chooseoption = gamepasses[math.random(1, #gamepasses)]
	
	bindableevent.OnInvoke = function(text)
		if text == "Buy" then
			marketplace:PromptGamePassPurchase(client, chooseoption.id)
		else
			return
		end
	end
	
	startergui:SetCore("SendNotification", {
		Title = chooseoption.title,
		Text = chooseoption.desc,
		Icon = "",
		Duration = 7,
		Button1 = "Buy",
		Button2 = "Cancel",
		Callback = bindableevent
		
	})
end

2 comments

0

I already solve the problem the same time you posted this thanks anyway for the nice explanation on why it did not work :)

0

Ah, no worries. @gamingwithjbthepro

This discussion is preserved as it was. New answers, comments, and votes are closed.