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

How to make a sound play when a user clicks on screen?

I'm trying to make a sound play when a user clicks on the screen, that's it.

I already know how to play a sound (when it's in the part itself):

script.Parent.[soundnamehere]:Play()

But I need the sound to play when the user clicks anywhere on the screen.

(Also, I'm trying to make it add to a leaderboard stat, it's optional to add an answer for this but I'd appreciate it!)

2 answers

You'd need to place this in a localscript in a client-side container (Such as StarterGui):

local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Button1Down:connect(function()
	script.Parent.Sound:Play()
end)

This is assuming you want it to click anywhere on the screen (no specific objects) and you want the sound to play immediately as you click down.

1 comment

0

Thanks!

(Put this in LocalScript)

player = game.Players.LocalPlayer
mouse = player:GetMouse()

local sound = --Put your sound here!

mouse.Button1Down:connect(function()
sound:Play()
end)

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