Code:



Ready1 = true
Ready2 = false
script.Parent.Touched:Connect(function(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h and Ready1 == true then
		Ready1 = false
		local folder = game.Workspace.Ambient
		for i,v in pairs(folder:GetChildren()) do
			v:Stop()
			if v.Name == "Wolf" then
				v.Script.Disabled = true
			end
			Ready2 = true
		end
		
	end
end)


script.Parent.TouchEnded:Connect(function(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h and Ready2 == true then
		wait(3)
		Ready2 = false
		local folder = game.Workspace.Ambient
		for i,v in pairs(folder:GetChildren()) do
			v:Play()
			if v.Name == "Wolf" then
				v.Script.Disabled = false
			end
			Ready1 = true
		end
		
	end
end)

Basically, when the player touches a part, audio stops playing. When he leaves the part the audio plays again. Simple right? It works correctly but whenever I stand still or move around the audio plays for a second then stops?

3 comments

0

Touched and TouchEnded are extremely, well, "touchy" events. Not only will they continuously fire as you walk around atop whatever trigger you're using (because the legs will be lifting), the Roblox idle animation will cause the same result. I recommend using Region3 to determine if a player has entered a given area. You could also use magnitude.

0

How would I make Region3 into a touched function?