I'm trying to make a sound play when you're swimming in water, but when I do it plays it even though it's already playing which makes an unwanted effect.

wait(1)
local P = game.Players.LocalPlayer
local character = workspace:WaitForChild(P.Name)

local s = Instance.new("Sound", P.PlayerGui)
s.SoundId = script.Underwater.SoundId

P.Character.Humanoid.Swimming:Connect(
	function()
		s:Play()
		end
)

5 comments

0

Wait, so the problem is that the sound already plays when the character isn't swimming, and it plays again when the player starts swimming?

0

So when you go idle the sound plays like normal, but when you are swimming then it keeps playing over and over starting from the begging 

0

Try adding an if statement to see if the sound is playing.

0

just add if s.IsPaused then

0

Just make a bool and make it false b4 u enter water and true when youre in water lol