I have just found out about the IsKeyDown service in Roblox not long ago and I’m trying to use it for when a character is blocking.
local function Input(input, gameProcessedEvent)
if isFKeyDown() then
game.ReplicatedStorage.BlockSystem.Hyperarmor:FireServer()
print("Hyperamor")
else
game.ReplicatedStorage.BlockSystem.NotBlocking:FireServer()
print("Not Blocking")
end
end
UIS.InputBegan:Connect(Input)
In this case when I hold F, the function takes a bit to detect it, and when I release F, the function detects it only after up to a few seconds. Am I using the IsKeyDown service correctly or are there any alternatives?
You can use UserInputService.InputBegan and detect the F key to set a value to true, and then set it to false with UserInputService.InputEnded to store whether or not the player is blocking. It should be a viable alternative.
local IsBlocking = false
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
IsBlocking = true
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
IsBlocking = false
end
end)
Make sure your doing this in a LocalScript and replicating it to the server!
Here’s a more organized method that should be the standard for all uses for this.
function input(iObj, ignore)
if ignore then return end
if input.KeyCode == Enum.KeyCode.F then
IsBlocking = iObj.UserInputState == Enum.UserInputState.Begin
end
end
UIS.InputBegan:Connect(input)
UIS.InputEnded:Connect(input)