I want to have music that stops playing once you touch a part, and after a few seconds, it plays again

You can write your topic however you want, but you need to answer these questions:

  1. What do I want to achieve? Music that stops playing once you touch a part, and plays after a few seconds.

  2. What is the issue? I have checked if anyone else had the same question, but i haven’t found exactly what i was looking for

  3. What solutions have you tried so far? I’ve mentioned before that i didn’t find any questions that fit with my question

local sound = workspace.sound -- change
local part = workspace.Part -- change

local timeTillStart = 3
local canTouch = true

part.Touched:Connect(function(hit)
	if game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) and canTouch then
		canTouch = false
		sound:Stop()
		
		delay(timeTillStart, function()
			sound:Play()
			canTouch = true
		end)
	end
end)

just change the variables and it should work

so the “timeTillStart” can be changed to the amount of seconds?

exactly, if its 5, then it will take 5 seconds till the sound starts again :joy:

thank you, one more question, what script do i use and in what part do i put the script?

you can use a server script if you want it to stop for every player in the game.

if not. use a local script and change the code to this

local sound = workspace.sound -- change
local part = workspace.Part -- change

local timeTillStart = 3
local canTouch = true

part.Touched:Connect(function(hit)
	local tPlr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if tPlr and tPlr == game.Players.LocalPlayer and canTouch then
		canTouch = false
		sound:Stop()

		delay(timeTillStart, function()
			sound:Play()
			canTouch = true
		end)
	end
end)

you can put the script inside the part that the player touches, but if its a local script you have to put it in som,ething like starterplayerscripts, or playergui

it’s ment to be global (filler filler)

Try this:
local music = game.workspace.music – Change this
local part = game.workspace.Part

part.Touched:Connect(function(hit)
music.Playing = false
wait(5) – Change this
music.Playing = true
end)

the thing is, the music is in the SoundService

local soundService = game:GetService(“SoundService”)
local sound = soundService:FindFirstChild(“Music”)
local part = game.Workspace.Part
part.Touched:Connect(function()
sound:Stop()
end)
wait(3) – wait for 3 seconds
sound:Play()

then this probably works if not then idk lol

So i change the (“Music”) part to the ID?

basically yeah replace the ID with the actual ID of the sound you want to play

image
do i change the “local part” text to the part that stops the music?
The script is inside the part, is that supposed to happen?

Yes sorry for the misunderstanding

the music still plays, even after touching the part

the errors say Line 5:

sound:Stop()

attempt to index nil with “stop”.

the script should only be used every time the music starts playing

local part = script.Parent
local music = game.SoundService:FindFirstChild(“Sound”)
local function partTouched(otherPart, objectPart)
music:Stop()
wait(3) – Change this
music:Play()
end
part.Touched:Connect(partTouched)

Put the script in the part

same result, music keeps playing, even after touching, error says line 4,
attempt to index nil with “stop”

i tested it, it works for me sorry i dont think i can think of anymore solutions sorry

could you share a video that shows that it works for you?