How to pass more than one parameter through Callbacks?

I am using Roblox’s “SendNotification” to accept or decline invites from other players. However, I need the players name to pass to another function. “SendNotification” only allows the players input to be passed through and not any extra parameters when setting a “Callback”. For example:

Callback = myBindableFunction -- This will only pass the players input & nothing else
Callback = myBindableFucntion:Invoke(answer) -- This will return nil
Callback = function() end -- This needs to be a BindableFunction

A visual example of what I want to achieve:

local function myFunction(otherPlayer)
	game:GetService("StarterGui"):SetCore("SendNotification",{
		Callback = function(myAnswer) -- How to make this a BindableFunction
			print(myAnswer, otherPlayer)
		end})
end

myFunction("Friend")

The reason I am doing it this way is because if both of my friends send me a notification the most recent friend will overwrite the other friend (When I set a variable to who sent me a notification)
For example:

local whatFriend = otherPlayer

I have already tried to make a table for players who’ve sent notifications and tried to make it a spawn function instead, and both results kept overlapping. I just need to figure out how to make the callback a function inside the scope of “SendNotification”

This is an example from Roblox’s CoreGUI Notification script and it’s what I am looking for.

sendNotificationInfo {
		GroupName = "Friends",
		Title = fromPlayer.Name,
		Text = "Sent you a friend request!",
		DetailText = fromPlayer.Name,
		Image = getFriendImage(fromPlayer.UserId),
		Duration = 8,
		Callback = function(buttonChosen) -- Why is their function activating but not mine?
			if buttonChosen == acceptText then
                AnalyticsService:ReportCounter("NotificationScript-RequestFriendship")
                AnalyticsService:TrackEvent("Game", "RequestFriendship", "NotificationScript")
                
				LocalPlayer:RequestFriendship(fromPlayer) -- "fromPlayer" is also in the scope

Hopefully I got my issue into words. I currently cannot think outside the box because I don’t know any other way about doing this, so now I am resulting to the devforum for some new brains to help me solve this. Any feedback or ideas would be appreciated!

I think I’ve been able to make what you are looking for let me know if not.

Screenshot_15

Alright, yes that’s what I am aiming for. However, inside the script how would I go about getting the players name who sent me a request and telling that player I pressed “Yes” or “No” onto their client? (Using the callback)

function Callback(answer)
	if answer == "Accept" then
		print("Accepted")
	else
		print("Denied")
	end
end

local Bindable = Instance.new("BindableFunction")
Bindable.OnInvoke = Callback

local function myFunction(otherPlayer)
	game:GetService("StarterGui"):SetCore("SendNotification", {
		Title = "Accept or Decline",
		Text = "You received an invitation from " .. otherPlayer,
		Duration = 10,
		Button1 = "Accept",
		Button2 = "Decline",
		Callback = Bindable
	})
end

myFunction("Friend")

This is what I have right now, so you can edit what’s in the callbacks if statements to send that back to the person who requested.

function Callback(answer)
	if answer == "Accept" then
		print("Accepted")
	else
		print("Denied")
	end
end

How would I go about passing the players name into this function for example:

function Callback(answer, otherPlayer) -- I need to pass the players name to this
	if answer == "Accept" then
		print("You accepted ".. otherPlayer)
	else
		print("You Denined ".. otherPlayer)
	end
end

There is a workaround, but depending how you plan to fire it you can use different methods, for example if you use a 2 way RemoteEvent to fire it you’ll have the username already, because firing the myFunction has to have a name within it.

myFunction("Friend") -- could make this string a variable

This it what it would end up looking like with a 2 way approach.

local inviter = "JohnDoe"

function Callback(answer)
	if answer == "Accept" then
		print("You accepted an invitation from "..inviter)
	else
		print("You denied an invitation from "..inviter)
	end
end

local Bindable = Instance.new("BindableFunction")
Bindable.OnInvoke = Callback

local function myFunction(otherPlayer)
	game:GetService("StarterGui"):SetCore("SendNotification", {
		Title = "Accept or Decline",
		Text = "You received an invitation from " .. otherPlayer,
		Duration = 10,
		Button1 = "Accept",
		Button2 = "Decline",
		Callback = Bindable
	})
end

myFunction(inviter)

I’ve tried this method before, but if 2 players send me a request, the first request will get overwritten with the second one.

If Player2 and Player3 send Player1 a request, Player1 will have 2 requests on their screen. If Player1 accepts Player3’s request first it will work fine. If Player1 accepts Players2’s request then since Player3 was set to that variable the script will think Player1 accepted Players3’s request.

Visual example:

local inviter = "JohnDoe"
function Callback(answer)
	if answer == "Accept" then
		print("You accepted an invitation from "..inviter)
	else
		print("You denied an invitation from "..inviter)
	end
end

local Bindable = Instance.new("BindableFunction")
Bindable.OnInvoke = Callback

local function myFunction(otherPlayer)
	game:GetService("StarterGui"):SetCore("SendNotification", {
		Title = "Accept or Decline",
		Text = "You received an invitation from " .. otherPlayer,
		Duration = 10,
		Button1 = "Accept",
		Button2 = "Decline",
		Callback = Bindable
	})
end

myFunction(inviter)
task.wait(1) -- After 1 second the request will be overwritten
inviter = "JaneDoe"
myFunction(inviter)

Screenshot_1
Screenshot_2

I need to make sure I tell the right player if I pressed accept or not.

Okay, In that case, I can come up with something different give me a few minutes.

Try this

function Callback(answer, inviter)
	if answer == "Accept" then
		print("You accepted an invitation from "..inviter)
	else
		print("You denied an invitation from "..inviter)
	end
end

local function myFunction(inviter)
	local Bindable = Instance.new("BindableFunction")
	Bindable.OnInvoke = function(answer)
		Callback(answer, inviter)
	end
	
	game:GetService("StarterGui"):SetCore("SendNotification", {
		Title = "Accept or Decline",
		Text = "You received an invitation from " .. inviter,
		Duration = 10,
		Button1 = "Accept",
		Button2 = "Decline",
		Callback = Bindable
	})
end

myFunction("JohnDoe")
2 Likes

I don’t know if I explained my post very well, but this worked perfectly! Thank you for helping me so quick :slight_smile: (Edit: I think I just was overcomplicating everything for myself lol, ty again)

No problem that’s what the DevForum is for.

This also helped me which is awesome lol

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