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 4 years ago
Edited 4 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 — 4y

2 answers

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

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!

0
Oh by the way @Pignite772 it didn't work. salexanderlucas -13 — 4y
Ad
Log in to vote
0
Answered by 4 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).

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)
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 — 4y

Answer this question