Hello, I am very confused, and someone with patience and kindness can explain to me somethings. I have made the following script:
function onKeyPress(key) if key == Enum.KeyCode.R then print("R was pressed") end end game.ContextActionService:BindAction(onKeyPress)
Can someone explain to me why in the wiki there are three parameters? Also, what is ContextActionService and BindAction? Thanks for reading, and again, sorry for my confusion. ~Yoman1776
ContextActionService is a service that can be used to bind user input to functions.
Also, whoever gave you that script may have been wrong in that set up.
BindAction is a function used to bind a specific key (using it's keycode), to function with some additional options.
http://wiki.roblox.com/index.php?title=API:Class/ContextActionService http://wiki.roblox.com/index.php?title=ContextActionService_tutorial
This is how you use it:
local serv = game:GetService("ContextActionService") function attack() print("he is attacking") end serv:BindAction("Attack",attack,false,Enum.KeyCode.One) wait(1) serv:UnbindAction("Attack")
These are the four parameters:
1)
The name of the action, it has to be unique.
2)
The function that gets called.
3)
Whether or not a button for this action will be created on a mobile.
4)
The key that gets pressed.