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)
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
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()
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)