Time loop getting faster and faster

what i want to achive : make the stand return to its original position after 1.3 seconds of it moving but m1ing resets the timer to 1.3 again

the problem :
when i m1 once everything works perfectly but when i m1 multiple times instead of the timer reseting everytime i m1 what happens is that with each m1 it starts to count down from 1.3 seconds a again while keeping the frist time existing like if the first m1 has 0.5 seconds left and i m1 again the 0.5 still keeps counting down and the second m1 starts counting down aswell so i have two counting at the same time and when one finishes it launches the script to return the stand

what i tried :
i’ve looked for similar topics and all of their solutions were to use a break in the loop but it didnt work for me

here is the code for it

 local m1Debounce = false
local active = false

length = 1.3

input.InputBegan:Connect(function(inputobject, typing)
	if typing == true then
		return
	end
	if inputobject.UserInputType == Enum.UserInputType.MouseButton1  then
		if m1Debounce == false then 
			print("m1")
			length = 1.3
			m1Debounce = true


			local StandTween = Tween:Create(plr.Character.Motor6D, TweenInfo.new(0.3), {C1 = CFrame.new(0, -0.3, 3)} )
			StandTween:Play()

			

	
			if active == false then
				active = true
			end
			task.wait(.3)
			m1Debounce = false
		end

		while active == true do
			if length <= 0 then

				local StandReturnTween = Tween:Create(plr.Character.Motor6D, TweenInfo.new(0.3), {C1 = CFrame.new(-2, -0.3, -2.5)} )
				StandReturnTween:Play()
				print("StandReturns")
				
				active = false
				break
			else

				task.wait(.1)
				length = length - 0.1
				print(length)
			end



		end

	end
end)

if you want to update the timer every time the player inputs the left mouse button, leave the length updater out of the debounce factor. The reason your timer doesn’t reset when you input left mouse button is because the length is only updated if debounce isn’t true.


if inputobject.UserInputType == Enum.UserInputType.MouseButton1 then
  length = 1.3
  if m1Debounce = false then
    print("m1")
    m1Debounce = true

didnt change much + i want the stand to only move forward if the player is able to m1 so moving it outside the if will make it even if the player cant m1 like in a cutsecne or on m1 cd the stand will still stay in its place

the stand is supposed to stay forward in this clip but it keeps going back and forth

i feel so stupid i just realized that i made a baisc mistake of not making a debounce for the while loop itself here is how the while loop looks after the edits

while active == true do
			wait()
			if loopDebounce == false then
				loopDebounce = true
				if length <= 0 then

					local StandReturnTween = Tween:Create(plr.Character.Motor6D, TweenInfo.new(0.3), {C1 = CFrame.new(-2, -0.3, -2.5)} )
					StandReturnTween:Play()
					print("StandReturns")

					loopDebounce = false
					active = false
					
					break
				else

					task.wait(.1)
					length = length - 0.1
					print(length)
				end
				loopDebounce = false
			end
			wait()
		end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.