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

How To Make Sound Play Once In A Block?

Asked by 5 years ago

I am new here so forgive me if I am doing anything wrong. Below is a script so when you touch a block it plays music. The script is very glitchy when someone is standing on the block when afk , it cuts the music and keeps replaying,how do I fix this.

Sorry if my explanation is all over the place.

local sound = Instance.new("Sound", Workspace)
sound.Pitch = 1 
sound.SoundId = "rbxassetid://902587196" 
sound.Volume = 1 
sound.Looped = false -- If you want the song to repeat after the song is done

script.Parent.Touched:connect(function()
        sound:play()
    end)
0
Thank you man. PhacYouBeech 17 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Just added a bool so that once its played it wont play again.

local sound = Instance.new("Sound", Workspace)
sound.Pitch = 1 
sound.SoundId = "rbxassetid://902587196" 
sound.Volume = 1 
sound.Looped = false -- If you want the song to repeat after the song is done
local playonce = false

script.Parent.Touched:Connect(function()
    if not playonce then
        playonce = true
            sound:play()
    end
end)
1
Thank you lol PhacYouBeech 17 — 5y
Ad

Answer this question