So, I am trying to get sound in different areas in my game. The way I did this was to make a part, insert two scripts and put this in the first one:
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
game.Players[hit.Parent.Name].PlayerGui.Sound:Resume()
end
end)
And this in the second one:
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
game.Players[hit.Parent.Name].PlayerGui.Sound:Resume()
end
end)
After doing that, I pressed play, ran into the area, everything worked. I was happy with that until I loaded into a custom character that I had made, and when I used that to run into the area or part, it played the music as normal but caused tremendous lag. I couldn't hardly move, so I thought maybe the script was running a gazillion times and causing lag, so I added debounce to it. This is what the first script looks like after adding debounce:
local Touched = false
script.Parent.Touched:connect(function(hit)
if not Touched then
Touched = true
if hit.Parent:FindFirstChild("Humanoid") then
game.Players[hit.Parent.Name].PlayerGui.Sound:Play()
end
end
end)
I added debounce to both of them, although I don't see why it needs it at all. Loaded up my normal character, everything worked fine. Loaded with my custom character, horrible lag same as before. I don't understand what could be causing this, as the script shouldn't cause any lag at all.
Any advice would be greatly appreciated.

3 comments
I am a little bit confused as to how to implement this into my script. Would I do if game.Players[hit.Parent.Name].PlayerGui.Sound.IsPlaying == false then
Yea, that seems right.
Well, I tried every single way I could think of of adding it to my script, and it still lags. I must be doing something wrong, just not sure what. Some advice on implementing this into my script would be wonderful. I'm still a relatively new scripter, so not too great at implementation of things yet.