Sound/Script playing WAY to fast ( I tried adding waits. didnt work.)

I made this script to detect if a part of the character is touched by a weld then destroy the weld. I added sounds to this script. When i touch an object with a weld it just sounds like: BRRRRRGWABBRRRRRRRGWABBBBBBRRRRRGWA. I tried adding a debouce and a wait also and if statement to detect if one of the sounds is playing. (it just made it sound even worse. Heres my code:

script.Parent.RightHand.Touched:Connect(function(part)
	local weld = part:FindFirstChild("Weld")
	local num = math.random(1,4)
	local debounce = false
	wait(0.5)
	if weld  then
		if debounce == false then
			debounce = true
			if num == 1 then
				script.Parent["Wood Breaking"]:Play()
			end
			if num == 2 then
				script.Parent["Lego Break Sound Effect"]:Play()
			end
			if num == 3 then
				script.Parent.glass_largesheet_break3:Play()
			end
			if num == 4 then
				script.Parent.metal_break:Play()
			end
			weld:Destroy()
		end
		debounce = false
		wait(0.1)


	end
end)

script.Parent.LeftHand.Touched:Connect(function(part)
	local weld = part:FindFirstChild("Weld")
	local num = math.random(1,4)
	local debounce = false
	wait(0.5)
	
	if weld  then
		if debounce == false then
			debounce = true
			if num == 1 then
				script.Parent["Wood Breaking"]:Play()
			end
			if num == 2 then
				script.Parent["Lego Break Sound Effect"]:Play()
			end
			if num == 3 then
				script.Parent.glass_largesheet_break3:Play()
			end
			if num == 4 then
				script.Parent.metal_break:Play()
			end
			weld:Destroy()
			debounce = false
		end
		wait(0.1)


	end
end)

script.Parent.LeftFoot.Touched:Connect(function(part)
	local weld = part:FindFirstChild("Weld")
	local num = math.random(1,4)
	local debounce = false
	wait(0.5)
	if weld  then
		if debounce == false then
			if num == 1 then
				script.Parent["Wood Breaking"]:Play()
			end
			if num == 2 then
				script.Parent["Lego Break Sound Effect"]:Play()
			end
			if num == 3 then
				script.Parent.glass_largesheet_break3:Play()
			end
			if num == 4 then
				script.Parent.metal_break:Play()
			end
			weld:Destroy()
			debounce = true
		end
		wait(0.1)


	end
end)

script.Parent.RightFoot.Touched:Connect(function(part)
	local weld = part:FindFirstChild("Weld")
	local num = math.random(1,4)
	local debounce = false
	wait(0.5)
	if weld  then
		if debounce == false then
			debounce = true
			if num == 1 then
				script.Parent["Wood Breaking"]:Play()
			end
			if num == 2 then
				script.Parent["Lego Break Sound Effect"]:Play()
			end
			if num == 3 then
				script.Parent.glass_largesheet_break3:Play()
			end
			if num == 4 then
				script.Parent.metal_break:Play()
			end
			weld:Destroy()
			debounce = false
		end
		wait(0.1)

	
	end
end)

Move the debounce variable outside of the connection.

1 Like

Didnt work

local debounce = false

script.Parent.RightHand.Touched:Connect(function(part)
	local weld = part:FindFirstChild("Weld")
	local num = math.random(1,4)
	local snap = part:FindFirstChild("Snap")
	
	wait(0.5)
	if weld or snap then
		if debounce == false then
			debounce = true
			if num == 1 then
				script.Parent["Wood Breaking"]:Play()
			end
			if num == 2 then
				script.Parent["Lego Break Sound Effect"]:Play()
			end
			if num == 3 then
				script.Parent.glass_largesheet_break3:Play()
			end
			if num == 4 then
				script.Parent.metal_break:Play()
			end
			weld:Destroy()
		end
		debounce = false
		wait(0.1)


	end
end)

you need to move the wait before the debounce/after you play the sound.

local debounce = false

script.Parent.RightHand.Touched:Connect(function(part)
	local weld = part:FindFirstChild("Weld")
	local num = math.random(1,4)
	local snap = part:FindFirstChild("Snap")
	
	if weld or snap then
		if debounce == false then
			debounce = true
			if num == 1 then
				script.Parent["Wood Breaking"]:Play()
			end
			if num == 2 then
				script.Parent["Lego Break Sound Effect"]:Play()
			end
			if num == 3 then
				script.Parent.glass_largesheet_break3:Play()
			end
			if num == 4 then
				script.Parent.metal_break:Play()
			end
			weld:Destroy()
			task.wait(0.5)
			debounce = false
		end

	end
end)

thanks it worked. Oh also what does task mean?

task lets you talk directly to roblox’s task manager, making waits faster and more accurate + other things

2 Likes