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

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

Asked by 7 years ago

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):

1script.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

Log in to vote
0
Answered by
GShocked 150
7 years ago

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

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

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.

0
Thanks! SindexMon 6 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

(Put this in LocalScript)

1player = game.Players.LocalPlayer
2mouse = player:GetMouse()
3 
4local sound = --Put your sound here!
5 
6mouse.Button1Down:connect(function()
7sound:Play()
8end)

Answer this question