i want to make it so if you just press a key and release it quickly it does a weak attack but if you hold it down AND then release after a period of time the attack is stronger
i know about inputbegan and inputended but how can i detect a keypress?
so how do i make these functions?
function KeyPress() attack() end function KeyDown() charge() end function KeyUp() attack() end
Hello, Bucwheed!
You can use a script like this one:
local PunchCharge = 0 function KeyUp() if PunchCharge < 10 then print("Not strong: " .. PunchCharge) -- Not too strong attack end if PunchCharge > 10 and PunchCharge < 100 then print("A bit strong: " .. PunchCharge) -- A bit more strong attack end if PunchCharge > 100 then print("Really strong: " .. PunchCharge) -- A really strong attack end PunchCharge = 0 end local UIS = game:GetService("UserInputService") local holdingEKey = false UIS.InputBegan:Connect(function(inputObject) if(inputObject.KeyCode==Enum.KeyCode.E)then holdingEKey = true while holdingEKey do PunchCharge = PunchCharge + 1 wait(0.001) end end end) UIS.InputEnded:Connect(function(inputObject) if(inputObject.KeyCode==Enum.KeyCode.E)then holdingEKey = false KeyUp() end end) -- Don't forget to change values if needed --
Hope this helps!
Good luck with your games!