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:
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:
Try This:
script.Parent.Touched:connect(function(h)
local hum = h.Parent:FindFirstChild("Humanoid")
if hum ~= nil then
game.SoundService.endmusicsong:play()
if game.SoundService.endmusicsong.IsPlaying then
game.Workspace.endmusicpar:Destroy()
end
end
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!
Oh by the way @Pignite772 it didn't work.
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).
local SoundService = game:GetService("SoundService")
local debounce = false
script.Parent.Touched:Connect(function(Hit)
if debounce then return end
debounce = true
if Hit.Parent:FindFirstChild("Humanoid") then
if SoundService.endmusicsong.IsPlaying then
script.Parent:Destroy()
else
SoundService.endmusicsong:Play()
end
end
wait(1)
debounce = false
end)
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Please paste your script into your post next time using the codeblock feature.