Please give your opinion on performance and optimization as well. Maybe even thread safety…
EDIT: event:FireServer() toggles whether not the action is ongoing on the server, that is why no arguments are passed.
Using a while loop (in this case a repeat until loop):
local debounce = true
userInputService.InputBegan:Connect(function(input, gpe)
if gpe then return end
if not debounce and input.KeyCode == Enum.KeyCode.F then
debounce = true
event:FireServer()
repeat task.wait(0.1) until not userInputService:IsKeyDown(Enum.KeyCode.F)
event:FireServer()
end
end)
Using InputEnded:
userInputService.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.F then
event:FireServer()
end
end)
userInputService.InputEnded:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.F then
event:FireServer()
end
end)