InputBegan firing twice

Hey! I’ve connected the InputBegan event to a function, and it seems like it fires twice even when I click once.

That should be alright, but a lot of the keys I use it for are toggling properties and features in the plane, therefore it ends up at the default value.

uis.InputBegan:Connect(function(i, p)
if p == false then
		    table.insert(keysBeingPressed, #keysBeingPressed + 1, i.KeyCode)
		    mainEvent:FireServer(i.KeyCode, i.UserInputType)

I’ve been trying to find the root to the problem for a while now. I found out that it fires on the same key, at the exact same time without firing InputEnded, which also fires twice obviously.

Seems like you’ve got a bit of a code block issue there. Remember to put your code inside 3 backticks in order for them to be formatted on the thread properly.

– Your code

I am unable to reproduce this error. I tried creating a repro with the code you posted on this thread (since you did not include a full example of relevant code and truncated it a little too much) and it only fires once as expected.

If you’re making a system that’s intended to check the keys being pressed, might I suggest using the event that’s intended for this, which is GetKeysPressed?

Thanks for telling me about the code block issue :relieved:

I think it might be a problem with my script, but I have no idea what the problem is. I need to use InputBegan though. Also, thanks for the reply.

Is there a specific reason why you cannot use the API that I listed? What you can probably do is have a “master” key to be pressed (i.e. Y), then use that method to see if the other keys are being pressed that are needed to proceed with the function (i.e. Ctrl).

1 Like

I’m so stupid that I didn’t think of that. Thank you so much for the help.