I’m working on a system that detects when you start holding a key to charge up a skill, and when you let go of the key to release it.
I’m worried about players abusing a possible bug that may allow them to ‘movestack’. Currently, I have a function that detects when the InputBegan, and a function that detects when the InputEnded. Both of them check if the Input is processed, so you don’t accidentally use a skill while typing in chat. Because of this, if you first press the key, then open the chat and let go of the key, it won’t fire the event for when the input ended which allows you to close the chat and press the key again without the original input ending.
Sorry if the explanation was confusing, I’ll attach a video of the bug in action (connected it to print() to give a better understanding in output).
Here’s the code:
local Player = game.Players.LocalPlayer
repeat wait() until game:IsLoaded()
local Character = Player.Character
local UserInputService = game:GetService("UserInputService")
local function KeycodeInputSender(KeyCode, State)
for i,v in pairs(Character.Values.Inputs:GetChildren()) do
if v.Name == KeyCode then
print(State.." pressing "..KeyCode)
v:FireServer(State)
end
end
end
UserInputService.InputBegan:Connect(function(Input, Processed)
if Processed then return end
if not Input.KeyCode then return end
KeycodeInputSender(Input.KeyCode.Name, "Began")
end)
UserInputService.InputEnded:Connect(function(Input, Processed)
if not Input.KeyCode then return end
KeycodeInputSender(Input.KeyCode.Name, "Ended")
end)
Solutions I have tried:
- Removing the check for processed in the second function, that detects when you stop holding it, results in the same bug except it ends the input twice instead of starting it twice.
- Removing the check for processed in the first function, that detects when you start pressing it, same result as “solution” #1.
- Super unideal but removing it from both, and results in the same thing as the last two.
If there’s something I should know for future posts or any further information you need please let me know it’s my first time posting