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

The difference between UserInputService and ContextActionService?

Asked by 8 years ago

What is the difference between the two, and in what situations is it best to use one over the other?

2 answers

Log in to vote
4
Answered by 8 years ago

The UserInputService can bind functions to user input via events such as "InputBegan", for example:

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
    local char = plr.Character
    local hum = char.Humanoid

function superJump(inputObject, GPE)
    if inputObject.KeyCode == Enum.KeyCode.U then
        hum.JumpPower = 150
        print("Super jump!")
    end
end

UIS.InputBegan:connect(superJump)

As for the ContextActionService, it can bind a SET of inputs to a function, additionally it can create GUI buttons on mobile for compatibility.

For example:

local CAS = game:GetService("ContextActionService")
    local plr = game.Players.LocalPlayer
    local char = plr.Character
    local hum = char.Humanoid

function speedUp(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        print("RUNNING!!!")
        hum.WalkSpeed = 100
    end
end

CAS:BindAction("speedingUp", speedUp, false, Enum.KeyCode.Y)

Also, a function bound through BindAction can be fired on all changes of the input's state, whether it began, ended, or changed.

Personally, if I were beginning keyboard input, I would go with the UserInputService for simplicity!

http://wiki.roblox.com/index.php?title=API:Class/UserInputService http://wiki.roblox.com/index.php?title=API:Class/ContextActionService

0
so with userinputservice, i use a specific input value (lets say the letter y) to do something for me, its the same with contextaction but it can unbind y under a condition, or bind something else under a condition? ProgramsMan 100 — 8y
0
Basically, I don't know too much about the CAS Strykebyte 45 — 8y
Ad
Log in to vote
2
Answered by
Cesire 45
8 years ago
Edited 8 years ago

ContextActionService can bind/unbind keybinds. UserInputService does the exact same thing as ContextActionService, exept that it cannot bind/unbind.

If you have a keyboard-press activated door, it's best to use ContextActionService, since you can bind a button to the door when you're close to it, instead of all the time.

If you want to have a quick respawn button, it's best to use UserInputService since you probably want to have the quick respawn feature active all the time.

http://wiki.roblox.com/index.php?title=API:Class/ContextActionService http://wiki.roblox.com/index.php?title=API:Class/UserInputService

Answer this question