Answer a notification using a key on the keyboard

Is there any way to bind a notification when you press a key?

I’m trying to make pressing the notification easier for pc players.

I plan it to work like this:

When a player presses e, he selects Button 1 and q to select Button 2.


local Player = game:GetService("Players").LocalPlayer

local function callback(Text)

if Text == "yes" then

game.ReplicatedStorage.CAUGHT_IN_4K_BACKROOMS:FireServer()

elseif Text == ("bruh") then

print ("NEVER GONNA GIVE YOU UP")

end

end

local NotificationBindable = Instance.new("BindableFunction")

NotificationBindable.OnInvoke = callback

while true do

wait(10)

game.StarterGui:SetCore("SendNotification", {

Title = "Sans";

Text = "Placeholder";

Icon = "http://www.roblox.com/asset/?id=5018130938";

Duration = "10";

Button1 = "yes";

Button2 = "bruh";

Callback = NotificationBindable;

})

end

I tried using the user input service, but unfortunately, it broke the entire script.

local Player = game:GetService("Players").LocalPlayer
local PlayerMod =require (game:GetService("Players").LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerMod:GetControls()


local function callback(Text)
if Text == "yes" then
print(Player.Name)
script.Parent.Realistic_backrooms_Glitch["Blue Bones"].Visible = false
game.ReplicatedStorage.CAUGHT_IN_4K_BACKROOMS:FireServer()
Controls:Enable()
script.Parent.Realistic_backrooms_Glitch.Frame.Transparency = 1

elseif Text == ("no") then
Controls:Enable()
script.Parent.Realistic_backrooms_Glitch["Blue Bones"].Visible = false
script.Parent.Realistic_backrooms_Glitch.Frame.Transparency = 1
game.ReplicatedStorage.BETRAYED_SANS1:FireServer()
script.Parent.Backrooms_Tip.Alert4.Visible = true
game.Workspace.Alerted:Play()
wait(10)
script.Parent.Backrooms_Tip.Alert4.Visible = false

end
end
local ew = true
local NotificationBindable = Instance.new("BindableFunction")
NotificationBindable.OnInvoke = callback

while true do
wait(1)
if game.Workspace.Sans ~= nil then
wait(40)
ew = false
Controls:Disable()
game.ReplicatedStorage.SANSFROZEN_BACKROOMS:FireServer()
script.Parent.Realistic_backrooms_Glitch["Blue Bones"].Visible = true
script.Parent.Realistic_backrooms_Glitch.Frame.Transparency = 0.9
game.Workspace["Undertale - snd_spearrise"]:Play()
game.StarterGui:SetCore("SendNotification", {
Title = "Sans";
Text = "placeholder";
Icon = "http://www.roblox.com/asset/?id=5018130938";
Duration = 30;

Button1 = "yes";
Button2 = "no";
Callback = NotificationBindable;
})
end
end

local key = game:GetService("UserInputService")

key.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
Controls:Enable()
script.Parent.Realistic_backrooms_Glitch["Blue Bones"].Visible = false
script.Parent.Realistic_backrooms_Glitch.Frame.Transparency = 1
game.ReplicatedStorage.BETRAYED_SANS1:FireServer()
script.Parent.Backrooms_Tip.Alert4.Visible = true
game.Workspace.Alerted:Play()
wait(10)
script.Parent.Backrooms_Tip.Alert4.Visible = false
elseif input.KeyCode == Enum.KeyCode.Q then
script.Parent.Realistic_backrooms_Glitch["Blue Bones"].Visible = false
game.ReplicatedStorage.CAUGHT_IN_4K_BACKROOMS:FireServer()
Controls:Enable()
script.Parent.Realistic_backrooms_Glitch.Frame.Transparency = 1

end
end)

Could you show your attempt in implementing UserInputService for your notification system?

sure

local Player = game:GetService("Players").LocalPlayer
local PlayerMod =require (game:GetService("Players").LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerMod:GetControls()


local function callback(Text)
if Text == "yes" then
print(Player.Name)
script.Parent.Realistic_backrooms_Glitch["Blue Bones"].Visible = false
game.ReplicatedStorage.CAUGHT_IN_4K_BACKROOMS:FireServer()
Controls:Enable()
script.Parent.Realistic_backrooms_Glitch.Frame.Transparency = 1

elseif Text == ("no") then
Controls:Enable()
script.Parent.Realistic_backrooms_Glitch["Blue Bones"].Visible = false
script.Parent.Realistic_backrooms_Glitch.Frame.Transparency = 1
game.ReplicatedStorage.BETRAYED_SANS1:FireServer()
script.Parent.Backrooms_Tip.Alert4.Visible = true
game.Workspace.Alerted:Play()
wait(10)
script.Parent.Backrooms_Tip.Alert4.Visible = false

end
end
local ew = true
local NotificationBindable = Instance.new("BindableFunction")
NotificationBindable.OnInvoke = callback

while true do
wait(1)
if game.Workspace.Sans ~= nil then
wait(40)
ew = false
Controls:Disable()
game.ReplicatedStorage.SANSFROZEN_BACKROOMS:FireServer()
script.Parent.Realistic_backrooms_Glitch["Blue Bones"].Visible = true
script.Parent.Realistic_backrooms_Glitch.Frame.Transparency = 0.9
game.Workspace["Undertale - snd_spearrise"]:Play()
game.StarterGui:SetCore("SendNotification", {
Title = "Sans";
Text = "placeholder";
Icon = "http://www.roblox.com/asset/?id=5018130938";
Duration = 30;

Button1 = "yes";
Button2 = "no";
Callback = NotificationBindable;
})
end
end

local key = game:GetService("UserInputService")

key.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
Controls:Enable()
script.Parent.Realistic_backrooms_Glitch["Blue Bones"].Visible = false
script.Parent.Realistic_backrooms_Glitch.Frame.Transparency = 1
game.ReplicatedStorage.BETRAYED_SANS1:FireServer()
script.Parent.Backrooms_Tip.Alert4.Visible = true
game.Workspace.Alerted:Play()
wait(10)
script.Parent.Backrooms_Tip.Alert4.Visible = false
elseif input.KeyCode == Enum.KeyCode.Q then
script.Parent.Realistic_backrooms_Glitch["Blue Bones"].Visible = false
game.ReplicatedStorage.CAUGHT_IN_4K_BACKROOMS:FireServer()
Controls:Enable()
script.Parent.Realistic_backrooms_Glitch.Frame.Transparency = 1

end
end)