So im making a game chase sequence when the sequence starts a music plays when it ends the music stops that is what im trying to do
heres the sound play script
debounce = false
script.Parent.Touched:connect(function(hit)
if not debounce then
debounce = true
if(hit.Parent:FindFirstChild("Humanoid")~=nil)then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local sound = script.Parent.Sound:Clone()
sound.Parent = player.PlayerGui
sound:Play()
wait(60)
end
debounce = false
end
end)
here is the sound stop script
script.Parent.Touched:connect(function(hit)
if(hit.Parent:FindFirstChild("Humanoid")~=nil)then
local sound = stop
local sound = script.Parent.Sound1:Clone()
sound.Parent = player.PlayerGui
end
end)
To play music when touching a part, you could start by doing:
Make SoundGroup inside of SoundService, then add Sound inside group.
You would also need to create a new local script inside of StarterPlayerScripts,
then to then paste in this code:
-- service
local soundService = game:GetService("SoundService")
-- variables
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- touch event
game.Workspace.Part.Touched:Connect(function(hit)
-- check if player touched the part
if character == hit.Parent then
-- loop through sound group and disable all sounds
for _, sound in pairs(soundService.SoundGroup:GetChildren()) do
sound:Stop()
end
-- play sound that you want
soundService.SoundGroup.Sound:Play()
end
end)
Haven’t tested the code, so you can do just that.
And if didn’t work then try solve the issue…