Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How To Make Sound Play Once In A Block?

Asked by 6 days 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 3 — 6d

1 answer

Log in to vote
0
Answered by 6 days 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 3 — 6d
Ad

Answer this question