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

I put a script inside a part the script should play a song if the part was touched why wont it work?

Asked by 5 years ago
Edited 5 years ago

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

0
Please paste your script into your post next time using the codeblock feature. iiAmBetterThanYouHa 20 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Try This:

1script.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
9end)

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!

0
Oh by the way @Pignite772 it didn't work. salexanderlucas -13 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

01local SoundService = game:GetService("SoundService")
02local debounce = false
03 
04script.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
18end)
0
Well i tried it and it didn't work. But, is there another way to play a sound without playing it a second time? You don't have to make the script but please tell me if i can and how. salexanderlucas -13 — 5y

Answer this question