I put a script inside a part the script was supposed to play a song and delete the part after if the part was touched.
This is the script:
https://prnt.sc/qztgmb
Try This:
1 | script.Parent.Touched:connect( function (h) |
2 | local hum = h.Parent:FindFirstChild( "Humanoid" ) |
3 | if hum ~ = nil then |
4 | game.SoundService.endmusicsong:play() |
5 | if game.SoundService.endmusicsong.IsPlaying then |
6 | game.Workspace.endmusicpar:Destroy() |
7 | end |
8 | end |
9 | end ) |
I've changed the :Play() from Line 5 to ".IsPlaying" IsPlaying can find if the music is currently playing or not. This is the variable you are looking for!
That would be because you play it and then destroy the part right after, not allowing it to play. Also, the Play
method doesn't return a boolean. I also added a debounce (for obvious reasons).
01 | local SoundService = game:GetService( "SoundService" ) |
02 | local debounce = false |
03 |
04 | script.Parent.Touched:Connect( function (Hit) |
05 | if debounce then return end |
06 | debounce = true |
07 |
08 | if Hit.Parent:FindFirstChild( "Humanoid" ) then |
09 | if SoundService.endmusicsong.IsPlaying then |
10 | script.Parent:Destroy() |
11 | else |
12 | SoundService.endmusicsong:Play() |
13 | end |
14 | end |
15 |
16 | wait( 1 ) |
17 | debounce = false |
18 | end ) |