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

How come object won't stop when I put keyup?

function Forward (actionName, state, actionInputObject)
	if state == Enum.UserInputState.Begin then
		repeat
		Truck.Thrust.Force = Truck.Thrust.force + Vector3.new(10,0,0)
		wait(0.01)
		until
		state == Enum.UserInputState.End
		
	
	end
	
end

contextActionService:BindAction("Forward",Forward,true,"t")

I'm trying to make an object stop increasing its thrust when I lift up the key and that is the until part. For some reason it isn't working and there are no errors. Basically, I want to increase thrust as I'm holding key down but stop increasing when I release key.

1 answer

✓ Accepted answer

Constant state

The state is the state of the event, not the input source. If you want a system which uses an input state instead of an event state, consider alternative input managers such as Freya Input and using the InputState object.


Alternatively, track it yourself.

local up = true
function Forward (actionName, state, actionInputObject)
    if state == Enum.UserInputState.Begin then
	up = false
        repeat
        Truck.Thrust.Force = Truck.Thrust.force + Vector3.new(10,0,0)
        wait(0.01)
        until up
	elseif state == Enum.UserInputState.End then
		up = true
    end
end

contextActionService:BindAction("Forward",Forward,true,"t")

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