Quickly detecting a conditional change

so im trying to instantly detect a condition change, currently a local boolean variable.

basically if you let go of the key(S) when falling (freefall), id like step to stay true until freefall is false.
just checking it over and over until freefall is false, surely theres a better way to do this?

elseif inputState == Enum.UserInputState.End then    
    if freefall == true and step == true then
        repeat wait() until freefall == false (!!)
        step = false
        stepmult = 1
    else
        step = false
        stepmult = 1
    end
end

ive experimented with making it an attribute/boolvalue and using getpropertychangedsignal, but it seemed to be quite heavy.

also, im using StateChanged on the humanoid to detect being airborne.

UserInputService.InputEnded:Connect(function(input, processed)
    if input.KeyCode == Enum.KeyCode.S and humanoid:GetState() == Enum.HumanoidStateType.Freefall then
        step = true
    end
end)

humanoid.StateChanged:Connect(function()
    if not humanoid:GetState() == Enum.HumanoidStateType.FreeFall then
        step = false
    end
end)

I’m not sure if this is what you’re asking for but from my understanding I would do it like this

2 Likes

thanks alot! my thought process was way off, this makes much more sense.

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