How do I play audio when clicked notification button

Hi, I made a notification that when a player joins, a warning will pop up. If the user clicks the Agree button, the notification would dismiss. But I would also want it to play audio / check sound.

This is what the notification looks like:
image

The script:

local function callback(Text)
	if Text == "Agree" then
		
	elseif Text == ("Decline") then
		game:GetService("Players").LocalPlayer:Kick("Declined warning") 

	end
	end

local NotificationBindable = Instance.new("BindableFunction")
NotificationBindable.OnInvoke = callback
--
game.StarterGui:SetCore("SendNotification",  {
	Title = "WARNING";
	Text = "This game contains flashing lights and loud audios. Not suitable for anyone with photosensitive epilepsy.";
	Icon = "rbxassetid://240664703";
	Duration = 100;
	Button1 = "Agree";
	Button2 = "Decline";
	Callback = NotificationBindable;
})
1 Like

It’s pretty simple. You just make a new sound instance if the callback text is “Agree,” set its SoundId, and then play it

local function callback(Text)
	if Text == "Agree" then
		local Sound = Instance.new("Sound", workspace)
		Sound.SoundId = "rbxassetid://123456789" -- change sound id
		Sound:Play()
	elseif Text == ("Decline") then
		game:GetService("Players").LocalPlayer:Kick("Declined warning") 
	end
end
1 Like