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

[RE] How to let a script know which button is pressed at a "SendNotification" Notification?

Hello.

I have this game where i want someone to friend request you. (A bot, not an actual player) But i have this problem.

I cant seem to figure out what button the player presses, There is no info online also. This is the script: (Localscript in startergui)

local NotificationBindable = Instance.new("BindableFunction")

game.StarterGui:SetCore("SendNotification", {
	Title = "Somebody";
	Text = "Sent you a friend request!";
	Icon = "http://www.roblox.com/asset/?id=3264340825";
	Duration = 5;
	Button1 = "Accept";
	Button2 = "Decline";
	Callback = NotificationBindable;
})

But i want the script to know what button you pressed. Example: if you click decline it will print decline in the output.

Can you help me do this?

1 comment

0

i think there is something called a local function for that

1 answer

✓ Accepted answer

Before you send the notification, use RemoteFunction.OnServerInvoke. Argument #1 passed into the function will give you the text of the button pressed. Try the code below: It should help you greatly!

local NotificationBindable = Instance.new("BindableFunction")
NotificationBindable.OnServerInvoke = function(text) -- hook onserverinvoke
    if text == "Accept" then -- if the button pressed is "Accept"
        -- do code when the button "Accept" is pressed
        else -- what to do if it is not accept
        -- do code when the button "Decline" is pressed
    end
end
game.StarterGui:SetCore("SendNotification", {
    Title = "Somebody";
    Text = "Sent you a friend request!";
    Icon = "http://www.roblox.com/asset/?id=3264340825";
    Duration = 5;
    Button1 = "Accept";
    Button2 = "Decline";
    Callback = NotificationBindable;
})

If this works, Please mark this as a solution Metatable out!

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