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

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

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

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.

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

(Put this in LocalScript)

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

local sound = --Put your sound here!

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

Answer this question