How can I use self with a BindAction?
ContextActionService:BindAction("LeftHoverboard", self:Rotate(), false, Enum.KeyCode.A)
ContextActionService:BindAction("RightHoverboard", self:Rotate(), false, Enum.KeyCode.D)
ContextActionService:BindAction("ForwardHoverboard", self:Move(), false, Enum.KeyCode.W)
ContextActionService:BindAction("BackwardHoverboard", self:Move(), false, Enum.KeyCode.S)
function HoverboardController:Move(actionName, actionState)
end
function HoverboardController:Rotate(actionName, actionState)
end
1 Like
you can’t use self in an environment where it doesn’t exist (in your case i am assuming you are using :BindAction() at the bottom of your script or something and not inside of a function)
self (when it is not already defined by a variable or parameter) is only assigned automatically in a function written with a semicolon. in your case, you should use HoverboardController instead of self
Sorry, it is in a function like so
function HoverboardController:Ride(board)
self.Board = board
ContextActionService:BindAction("LeftHoverboard", self:Rotate(), false, Enum.KeyCode.A)
ContextActionService:BindAction("RightHoverboard", self:Rotate(), false, Enum.KeyCode.D)
ContextActionService:BindAction("ForwardHoverboard", self:Move(), false, Enum.KeyCode.W)
ContextActionService:BindAction("BackwardHoverboard", self:Move(), false, Enum.KeyCode.S)
end
this is how I would do it
ContextActionService:BindAction(
'Ex',
function(...)
self:Method(...)
end,
false,
Enum.KeyCode.A
)
1 Like