Inspect animation canceling help

Hello, im trying to do an inspect animation, but task.wait() doesnt stop, i know you cant stop it (i think) so im asking if theres a better way to stop the rest of the code, for an example:

if i press G i want the task.wait(6.3) to stop and jump down to the rest of the code

InspectingBool.Value = true

task.wait(6.2)

InspectingBool.Value = false

--imagine theres 60 line of code here and i press G, so the task.wait() stops and straight up jump to the if statement below

if input.KeyCode == Enum.KeyCode.G then
    InspectingBool.Value = false
    --imagine theres more code bellow
end

the problem i have is that when i press G the inspect animation stops, but when i press G to replay it the task.wait() hasnt stoped counting down, so the “bug fixing” if statements bellow the task.wait() runs and stops the inspect animation

Code(if u find it easier):

			task.wait(6.2) -- the task.wait() i want to "stop"
			
			InspectingBool.Value = false
			
			if InspectingBool.Value == true and TomahawkIdleAnim.IsPlaying then
				TomahawkIdleAnim:Stop()
			end
			
			if not TomahawkInspectAnim.IsPlaying then
				InspectingBool.Value = false
			end
			
			if InspectingBool.Value == false and inspecting == false and not TomahawkInspectAnim.IsPlaying then
				TomahawkIdleAnim:Stop()
			end
			
			if inspecting == true then
				inspecting = false
			end
			
			if CanCancel == true then
				CanCancel = false
			end
			
			if TomahawkInspectAnim.IsPlaying and TomahawkIdleAnim.IsPlaying then
				warn("> attempt to fix inspect")
				TomahawkIdleAnim:Stop()
				if TomahawkInspectAnim.IsPlaying and TomahawkIdleAnim.IsPlaying then
					warn("> attempt to fix inspect failed")
				end
				if TomahawkInspectAnim.IsPlaying and not TomahawkIdleAnim.IsPlaying then
					warn("> attempt to fix inspect success")
				end
			end
			
			if inspecting == false and InspectingBool.Value == true and TomahawkInspectAnim.IsPlaying then
				TomahawkIdleAnim:Stop()
				if InspectingBool.Value == true and not TomahawkInspectAnim.IsPlaying then
					warn("> inspectbool > [true] while inspect animation not playing; inspectbool reset > [false]")
					InspectingBool.Value = false
				end
			end
			
			if TomahawkInspectAnim.IsPlaying and inspecting == false then
				inspecting = true
				warn("> inspecting variable reset > [true]")
			end
			if TomahawkIdleAnim.IsPlaying and TomahawkInspectAnim.IsPlaying then
				TomahawkIdleAnim:Stop()
				warn("> animation bug found; idle animation reset")
				if inspecting == false then
					inspecting = true
				end
			end
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
		end
	end
	if input.KeyCode == Enum.KeyCode.G and inspecting == true and CanCancel == true and TomahawkInspectAnim.IsPlaying then
		task.wait(0.05)
		InspectingBool.Value = false
		inspecting = false
		CanCancel = false
		TomahawkInspectAnim:Stop()
		print("> inspecting canceled")
		
		if TomahawkInspectAnim.IsPlaying and inspecting == true then
			TomahawkInspectAnim:Stop()
			inspecting = false
		end
		if not TomahawkIdleAnim.IsPlaying and not TomahawkInspectAnim.IsPlaying and inspecting == false then
			TomahawkIdleAnim:Play()
			TomahawkInspectAnim:Stop()
		end
		if inspecting == false and TomahawkInspectAnim.IsPlaying then
			inspecting = false
			TomahawkInspectAnim:Stop()
		end
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
	end
end)
1 Like