Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago
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

Log in to vote
0
Answered by 7 years ago

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")
0
Just doesn't seem top be working @seanbenish robloxiveboy 25 — 7y
Ad

Answer this question