Help on creating something similar to a debounce so my script doesn't break

I’m trying to make my script not break whenever the player says something else before the code ends.

It breaks any time the code hasn’t finished and the player says something else. I recorded something so it should help you understand.

The players mouth is supposed to close when the sentence is finished but it infinitely stays open.

I tried adding a debounce but it didn’t seem like it worked.

Anything helps!

player.Chatted:Connect(function(text) --see's if player has said something

	--vars
	local amt = text.len(text) --detects message length
	local waittime = amt / math.random(6, 7.4) --how long the mouth stays open (maths)
	
	local currentmouth = mouth.Texture --saves mouth tex
	
	--texchange
	mouth.Texture = "rbxassetid://6376349647" --changes decal
	
	--sound play
	sound.Playing = true
	
	--wait
	wait(waittime) --waits the chosen time
	
	--sound end
	sound.Playing = false
	
	--origtex
	mouth.Texture = currentmouth --reverts to original mouth
	
end)

That’s the part of the code that makes the player talk.

so this doesn’t work?

local debounce = false

player.Chatted:Connect(function(text) --see's if player has said something
	if not debounce then
		debounce = true
	
		--vars
		local amt = text.len(text) --detects message length
		local waittime = amt / math.random(6, 7.4) --how long the mouth stays open (maths)
	
		local currentmouth = mouth.Texture --saves mouth tex
	
		--texchange
		mouth.Texture = "rbxassetid://6376349647" --changes decal
	
		--sound play
		sound.Playing = true
	
		--wait
		wait(waittime) --waits the chosen time
	
		--sound end
		sound.Playing = false
	
		--origtex
		mouth.Texture = currentmouth --reverts to original mouth
		end
	debounce = false
end)

if so, that’s really strange, it looks like it should work.

1 Like

Huh I guess what I wrote didn’t work for some reason, but thank you!

1 Like
local amt = text.len(text) --detects message length

I see the issue here, I believe you meant string.len.

1 Like