Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I check which option a player chose when using setcore:sendnotification?

Asked by 4 years ago

function lol(text) print(text) end game.StarterGui:SetCore("SendNotification",{ Title = "hi"; Time = 5; Text = "hlol"; Button1 = "yes"; Button2 = "no"; callback = lol(); })

I tried connecting a callback to a function, but it prints nil everytime with no errors. How do I check which option a player clicked?

0
When setting a callback, just remember that you need to do = lol, not = lol(). In the first, you are setting the callback to the function. In the second, you are setting the callback to the return value of the function, which, in this case, is nothing. User#26971 0 — 4y

1 answer

Log in to vote
0
Answered by
cegberry 432 Moderation Voter
4 years ago

A callback needs to be a BindableFunction, not actually a function, this is a short example:

local BindableFunction = Instance.new("BindableFunction")

function onClicked(option)
if option == "yes" then
-- what to do if the player presses yes
elseif option == "no" then
-- what to do if the player presses no
end
end

BindableFunction.OnInvoke = onClicked -- set our bindable function's oninvoke to our func

game.StarterGui:SetCore("SendNotification",{
    Title = "hi";
    Time  = 5;
    Text = "hlol";
    Button1 = "yes";
    Button2 = "no"; 
    callback = BindableFunction
})
Ad

Answer this question