This seems like a basic question, but still - I want to make this a script and not a LocalScript so that everyone can hear the sound, not just the player clicking it.
1 | function PlaySound( ) |
2 | script.Parent.Parent.Horn: Play( ) |
3 | end |
4 | script.Parent.MouseButton 1 Click:connect (PlaySound) |
Never trust the client. Use a RemoteEvent instead for better gameplay. I don't think you would let exploiters play their sounds so everyone can hear it.
SERVERSCRIPT
01 | local Event = Instance.new( "RemoteEvent" ); |
02 | Event.Name = "Sound Event" ; |
03 | Event.Parent = game:GetService( "ReplicatedStorage" ); |
04 |
05 | Event.OnClientEvent:Connect( function (Player, check) |
06 | if check = = "PLAY_SONG_EVENT" then |
07 | local h = Instance.new( "Sound" ) |
08 | h.Parent = Player:WaitForChild( "PlayerGui" ) |
09 | h:Play() |
10 | -- do other things if you want to, as this is only an example. |
LOCALSCRIPT
1 | local Event = game:GetService( "ReplicatedStorage" ):WaitForChild( "Sound Event" ) |
2 | Event:FireAllClients( "PLAY_SONG_EVENT" ) |