Hello everyone,
I was working on one of my projects when I noticed strange behavior out of the blue. After some time and digging I narrowed it down to this function of a script for one of my Lock On setups
game:GetService("UserInputService").InputBegan:Connect(function(obj,gameProcess)
if gameProcess then return end
print("CALL TIME : " .. tostring(tick()))
if (tick() - lastInputCall) < .1 then
return
end
lastInputCall = tick()
print("KEY CODE CHECK : " .. tostring(obj.KeyCode))
if (obj.KeyCode == Enum.KeyCode.LeftControl or obj.KeyCode == Enum.KeyCode.ButtonL1) and hum.Health > 0 and not combatData.SpectatorMode.Value and combatData.CanAttack.Value and not combatData.QuickTimeClash.Value and not combatData.CanBeFinished.Value and not combatData.InFinisher.Value and not combatData.AttackVisual.Value and not clientSideAttacking then
print("CALLING HANDLER FOR LOCK ON")
handleLockOnToggle()
end
if (obj.KeyCode == Enum.KeyCode.Q or obj.KeyCode == Enum.KeyCode.ButtonR1) and hum.Health > 0 and not combatData.QuickTimeClash.Value and not combatData.CanBeFinished.Value and not combatData.InFinisher.Value and checkSwitchTarget() then
if lockOnMode then
local target = findTarget(true)
if target then
setTarget(target)
end
end
end
end)
(Please excuse the lack of readability in the if statements)
For whatever reason the InputBegan event is always fired twice, and I can’t figure out exactly why.
I’ve tested it for being multiple input methods, I’ve tested it for duplicates being called, I’ve tried almost everything but nothing has fixed it. It even occurs in the live version of the game.
The most recent fix I’ve attempted was using tick()
to determine the input times, but even this didn’t work. On the 3rd line of the function is an “escape” for whichever method call is second and even setting the number requirement to something that should prevent it hasn’t worked. The time delay difference is near instant being around .0002 seconds.
The script is in a folder under StarterCharacterScripts
I’m not sure how to fix this. Does anyone have a possible solution or explanation? Thank you in advance.
(Side note, yes I have searched on the developer forums. There was a post made about this back in Feb. with no solution.)
Edit: I have just tested this with a new local script with the following code:
game:GetService("UserInputService").InputBegan:Connect(function(v)
print("INPUT : " .. tostring((v.KeyCode)))
end)
In the first place this code repeated twice. In the second place (an empty baseplate) it repeats twice on the first input then acts normally. It repeats the double fire if you click off of studio and then back onto it though.