I want to make a game where the music is different in each area. Like a button that plays a specific song when you step on it. I had it working but the songs overlapped. Can anybody tell me how to make this button?

function onTouched(hit) script.Parent.Music:play() end wait (1) script.Parent.Touched:connect(onTouched)

script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild('Humanoid')then game.Players[hit.Parent.Name].PlayerGui.Track2:Stop() game.Players[hit.Parent.Name].PlayerGui.Track1.Volume=1 game.Players[hit.Parent.Name].PlayerGui.Track1:Play() end end)

5 comments

0

Multiple sounds playing could be because you're not checking if one is already playing and the lack of a debounce to prevent the Touched event being spammed.

0

Provide your attempt so we can see what you're doing.

0

the scripts arent working at all anymore but I will provide them anyway : function onTouched(hit) script.Parent.Music:play() end wait (1) script.Parent.Touched:connect(onTouched)

0

script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild('Humanoid')then game.Players[hit.Parent.Name].PlayerGui.Track2:Stop() game.Players[hit.Parent.Name].PlayerGui.Track1.Volume=1 game.Players[hit.Parent.Name].PlayerGui.Track1:Play() end end)

0

Edit your original post. Don't put it in the comments. Edit button is right below this comment section.