I need this script to play a sound for someone who just joined and only once. I have a sound with the ID set in the StarterGUI file.
1 | local player = game.Players.PlayerAdded:connect( function (player) |
2 | local sound = player.PlayerGui.Sound |
3 | sound:Play() |
4 | end ) |
Use WaitForChild for every descendant of player. i.e.
1 | local sound = player:WaitForChild( "PlayerGui" ):WaitForChild( "Sound" ) |
just make is stop after 2 seconds
1 | local player = game.Players.PlayerAdded:connect( function (player) |
2 | local sound = player.PlayerGui.Sound |
3 | sound:Play() |
4 | wait( 2 ) |
5 | sound:Stop() |
6 | end ) |
If you'd like to only play the sound once, simply turn the Looped property off!
1 | game.Players.PlayerAdded:connect( function (player) |
2 | local sound = player.PlayerGui.Sound |
3 | sound.Looped = false |
4 | sound:Play() |
5 | end ) |