What is the difference between the two, and in what situations is it best to use one over the other?
The difference between UserInputService and ContextActionService?
2 answers
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
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
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
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?
Basically, I don't know too much about the CAS