How to detect a held button press?

I’m making a tile based movement game and I’m trying to get the inputs situated, I made a function that detects valid input while the game loop is running; But I wonder if I can make it somehow detect whether an input is held or not.

There are two scripts I have for detecting input, here is one:

local gameLoop = {}

local userInputService = game:GetService("UserInputService")

local inputMod = require(script.Parent.Input) --input module
local map = require(script.Parent.Map)

function gameLoop.run(name, floor, team)
	local newInput = inputMod.new()
	local regInput = newInput.regInput
	
	map.generate(name)
	
	while true do
		regInput(yield(userInputService.InputBegan)) --this is what detects inputs
	end
end

function yield(source) --yielding everything in a loop until an input is pressed
	while true do
		local input, gameProcessed = source:Wait()
		if gameProcessed then 
			continue
		end
		if input.UserInputType == Enum.UserInputType.Keyboard then
			return input
		end
	end
end

Here is the other:

local input = {
	["gridSize"] = 7,
	["controls"] = {}
}

function input.new()
	input.controls = {
		_G.PlayerData.Settings.Controls.control1,
		_G.PlayerData.Settings.Controls.control2,
		_G.PlayerData.Settings.Controls.control3,
		_G.PlayerData.Settings.Controls.control4
	}
	
	return input
end

function input.regInput(keyCode)
	local key = input:inputValid(keyCode.KeyCode)
	if key then
		print(key) --Haven't gotten around to doing anything with this, it just returns the control pressed, it could say whether it's held or not in the end however.
	end
end

function input:inputValid(keyCode)
	for i, j in pairs(input.controls) do
		if keyCode == j then
			return keyCode.Name
		end 
	end
end

return input

If anyone has any ideas, please let me know! Thanks!

input & output

local holding = false

input
holding = true
end

output
holding = false
end

Why you dont simple get the keys pressed?

local UIS = game:GetService("UserInputService") 
for i,v:InputObject in ipairs(UIS:GetKeysPressed()) do 
-- You can check v.KeyCode here and do what you want
end