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

How can I do if statement if key is down in contextActionService?

function Forward (actionName, actionInputState, actionInputObject)
--I need something here to notice if key is down do that
Truck.Thrust.Force = Truck.Thrust.force + Vector3.new(100,0,0)
	wait(0.1)
	
end

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

Basically what I noted up there. I need some thing at that space possibly an if statement to detect if the t key is down and if it his held. Basically I want Truck.thrust.Force line to run as long as the t key is down not when you press it once or etc.

1 answer

The key's status is marked with the "actionInputState" parameter. If the keypress starts, then it will have a value of Enum.UserInputState.Begin, or 0. For more information, see: http://wiki.roblox.com/index.php?title=API:Enum/UserInputState

Example:

local function Forward (actionName, actionInputState, actionInputObject)
	if actionInputState == 0 then
		Truck.Thrust.Force = Truck.Thrust.Force + Vector3.new(100,0,0)
	end
end

game.GetService("ContextActionService"):BindAction("Forward",Forward,true,"t")

1 comment

0

Just doesn't seem top be working @seanbenish

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