I recently was connecting the R key, to a function, using ContextActionService:BindAction().
I am almost certain that this is a roblox bug,as I have plenty of experience with ContextActionService, but decided to make a Scripting Support post to confirm it.
Code:
Function:
function RPressed(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
print("YEET")
end
end
Connection:
ContextActionService:BindAction("RPressed", RPressed, false, Enum.KeyCode.R)
The issue is, that when the game begins, RPressed() is fired once by the BindAction, even though I have pressed no keys.
When I start the game with the code I posted above, âYeetâ is printed into the output:
After firing the function once, the BindAction() stops working, and does not fire RPressed() again when I press the R key. The BindAction() triggers the function when the script starts, and renders useless after that. This only happens about 50% of the time.
Before I create this topic, I wanted to mention that I did find a solution to this.
If I add a wait(3)( Which I am assuming is about the time it takes the game to fully load. I tried using game.Loaded:Wait(), though, and it doesnât fix the issue. ), directly before calling BindAction(), the code works as intended. I have no idea why this is the case, but it does fix the problem. However, it is extremely strange that I have to do this at all, so I am hoping to find a solution that makes more sense, and is not dependent on waiting an obscure amount of seconds.
Does anyone have any ideas of what is causing this?
Thanks for reading!