Landing gear damage function

I’m trying to have a plane system efficiently check for the following conditions:

  1. The landing gear is down
  2. The plane is travelling at a certain speed or greater

If both of these conditions remain true for a certain timeframe, the landing gear should be destroyed.

I already have a function in place that works, but it’s extremely inefficient - does anyone have an idea for a more efficient function?

The code you sent in direct message looks good to me!

One thing you could do differently instead of having a counter variable is keep track of the time you out your gear down:

gearDownStartTime = tick()

and then change the function to:

function GearDamage()
	if dead then return end
	
	while (gearDown and speed.Value >= gearThreshold) do
		print("Gear's down, going too fast")
		
		if tick() - gearDownStartTime >= 10 then
			print("oop ded wheels")
			plane.Misc.LandingGear:Destroy()
			gearIntact = false
			return
		end
		
		wait(1)
	end
end

Something like

plane.speedChangedEvent:Connect(function(speed)
    if gearIsDown and speed > threshold then
        breakGear()
    end
end)

This looks like a great solution, but it seems to disable the landing gear almost immediately - how do I increase the delay? I can’t find tick() in the API.