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:
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!
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)