Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How To Make Sound Play Once In A Block?

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)

1 comment

0

Thank you man.

1 answer

✓ Accepted answer

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 comment

1

Thank you lol

This discussion is preserved as it was. New answers, comments, and votes are closed.