Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Debounce isn't working causing tweening not to work?

I am trying to make a tutorial for my game which tweens the information but its not working!

local deb = false

script.Parent.MouseButton1Click:connect(function()

	if not deb and script.Parent.Parent.Story.Text == "Ok nub, your goal is to become the best, dankest, mlgest quickscoper in the world. I'll show you how to quickscope, ya nub." then
	deb = true
	script.Parent:TweenPosition(UDim2.new(-1,0,.575,0), "Out", "Elastic", 2)
	script.Parent.Parent.Story:TweenPosition(UDim2.new(-1,0,.375,0), "Out", "Elastic", 2)
	script.Parent.Parent.SkipButton:TweenPosition(UDim2.new(-1,0,.675,0), "Out", "Elastic", 2)

	script.Parent.Parent.Story.Text = "Ok nub, this is your doritos. You get doritos by quickscoping noobs and stealing their doritos, and by running a smuggling business."
	script.Parent.Parent.Display:TweenPosition(UDim2.new(0,0,0,0),"Out", "Elastic", 2)
	script.Parent:TweenPosition(UDim2.new(.375,0,.575,0), "Out", "Elastic", 2)
	script.Parent.Parent.Story:TweenPosition(UDim2.new(.25,0,.3,0), "Out", "Elastic", 1)

	
	elseif not deb and script.Parent.Parent.Story.Text == "Ok nub, this is your doritos. You get doritos by quickscoping noobs and stealing their doritos, and by running a smuggling business." then
	deb = true
	script.Parent:TweenPosition(UDim2.new(-1,0,.575,0), "Out", "Elastic", 2)
	script.Parent.Parent.Story:TweenPosition(UDim2.new(-1,0,.375,0), "Out", "Elastic", 2)

	script.Parent.Parent.Story.Text = "Look nub, a wild skrub lord has appeared! Quickscope it for some doritos!"
	script.Parent:TweenPosition(UDim2.new(.375,0,.575,0),"Out", "Elastic", 2)
	script.Parent.Parent.Doritos:TweenPosition(UDim2.new(.375,0,.25,0), "Out", "Elastic", 2)
	script.Parent.Parent.Story:TweenPosition(UDim2.new(.25,0,.3,0), "Out", "Elastic", 1)
	
	
	elseif not deb and script.Parent.Parent.Story.Text == "Look nub, a wild skrub lord has appeared! Quickscope it for some doritos!" then
	deb = true
	script.Parent:TweenPosition(UDim2.new(-1,0,.575,0), "Out", "Elastic", 2)
	script.Parent.Parent.Story:TweenPosition(UDim2.new(-1,0,.375,0), "Out", "Elastic", 2)

	script.Parent.Parent.Story.Text = "Ok nub, this is your menu, everything useful will be in here, go ahead and purchase some items! Thats all I can teach you for now!"
	script.Parent:TweenPosition(UDim2.new(.375,0,.575,0),"Out", "Elastic", 2)
	script.Parent.Parent.MenuButton:TweenPosition(UDim2.new(.375,0,.805,0), "Out", "Elastic", 2)
	script.Parent.Parent.Story:TweenPosition(UDim2.new(.25,0,.3,0), "Out", "Elastic", 1)
	
	elseif not deb and script.Parent.Parent.Story.Text == "Ok nub, this is your menu, everything useful will be in here, go ahead and purchase some items! Thats all I can teach you for now!" then
	deb = true
	script.Parent:TweenPosition(UDim2.new(-1,0,.575,0), "Out", "Elastic", 2)
	script.Parent.Parent.Story:TweenPosition(UDim2.new(-1,0,.375,0), "Out", "Elastic", 2)
		
	wait(.5)
	deb = false	
	end	
end)

1 answer

✓ Accepted answer

This is rather cancerous to look at... but the great Perci has prevailed against the dark forces of strings and bad tabbing and has retained his eyesight!


Anyways, notice that you always set deb to true after a condition. This is correct, clap clap.

However, the only time you set deb back to false is in the last condition.

elseif not deb and script.Parent.Parent.Story.Text == "Ok nub, this is your menu, everything useful will be in here, go ahead and purchase some items! Thats all I can teach you for now!" then
	deb = true
	script.Parent:TweenPosition(UDim2.new(-1,0,.575,0), "Out", "Elastic", 2)
	script.Parent.Parent.Story:TweenPosition(UDim2.new(-1,0,.375,0), "Out", "Elastic", 2)
	
	wait(.5)
	deb = false --right here
end 

So if this final condition passes, deb will be set to false, allowing the code to run again. But if any other condition passes, deb won't be set to false, not allowing the code to run ever again.



You have a couple options here. One is to just set deb to false in every condition.

if not deb and otherCondition1 then
	deb = true
	--stuff
	deb = false
elseif not deb and otherCondition2 then
	deb = true
	--stuff
	deb = false
elseif not deb and otherCondition3 then
	deb = true
	--stuff
	deb = false
end

However, I think a better option would be to use two if statements: One for the debounce, another for the other conditions.

if not deb then
	deb = true

	if otherCondition1 then
		--stuff
	elseif otherCondition2 then
		--stuff
	elseif otherCondition2 then
		--stuff
	end

	deb = false
end

This discussion is preserved as it was. New answers, comments, and votes are closed.