Making an input system for a Fighting Game compatible with holding down keys

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make an input system that can also work for holding down keys such as block.

  2. What is the issue? Include screenshots / videos if possible!
    Whenever you press a key while holding down block it kind of breaks everything.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried looking on the Developer Hub, I found nothing.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Input , IsTyping) 
	if not IsTyping then
		script.Parent.KeyBindEvent:FireServer(UIS:GetStringForKeyCode(Input.KeyCode))
		end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

I tried and failed quite a few times with vehicle/crane commands. Every time I ended an input most of the others stopped working (rotating the crane while dropping the bucket and extending the bucket outwards) but something that worked for me was to make 2 functions, simplified below:

--[[
Input began function
     control inputs added
end
Input ended function
     control input or inputs that ended are stopped
     call input began function to keep the unstopped controls going
end
]] 

Not sure if this works for a server script though since I have it locally in the player’s scripts.

1 Like

You can use loops to whenever the player is holding the key.
I’ll give you an example @Scottifly I think you mean the same? if so then this will help you.

local uis = game:GetService("UserInputService")
local isHolding = false -- Debounce whenever the key is getting pressed

uis.InputBegan:Connect(function(obj) -- When an input began
    if obj.KeyCode == Enum.KeyCode.E then -- If the input key is "E"
         isHolding = true -- holding
   end
end)

uis.InputEnded:Connect(function(obj) -- When an input ended (key unpressed)
    if obj.KeyCode == Enum.KeyCode.E then -- If the key that got unpressed is "E"
         isHolding = false -- not holding anymore
   end
end)

while task.wait() do -- We are not using isHolding statement here because once the key is dispressed then it will never run again.
    if isHolding then -- whenever the key is getting pressed
        print('E key is getting pressed!') -- Does your code
    end
end

If you didn’t mean this then, re-explain it to me please.

1 Like

I tried a version of that, but I have up to 9 inputs for the vehicle controls.

When the InputBegan function is run there are 9 if obj.Keycode == sections of code in an if else end format.
When the InputEnded function is run there are 9 if not obj.Keycode == sections of code in an if else end format with a call for the InputBegan function just before the end.
I then call the InputBegan and InputEnded functions at the bottom.

I’m just writing this from memory, and in reality I’m not a great scripter, but this works well since if I’m holding 4 keys down and release 1 the other 3 inputs still register. It also keeps from having a continuously running while loop when the vehicle isn’t being used.

1 Like

I wanna detect whenever they press any numbers (like 1-9 maybe even 0) cause I’m creating a fighting game a bit like SoulShatters and Untitled Combat Demo. I also wanna detect when they hold down F so you can block attacks.

1 Like