I have a script to make a sound play when inside of an invisible part with no collide on but when you jump inside of it the sound plays twice while the first sound is already playing. You can see what I mean here. And I don't know how to end the sound playing if the user leaves the part it was in. Can anyone please help me with this? The script is the child of a part with a sound that is also a child of the part. I'm not that good at scripting btw.
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(2)
end
debounce = false
end
end)

2 comments
so should the touch ended be in a separate script as the child of the part or along with the script with the first script you sent
It should be in the same.