Need help with debounce system (make player move right if he Hold D on keyboard don't ask me why)

Guys idk how to make a debounce system to avoid spam issue so can anyone edit my script and make debounce system on it and ty

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local Character = player.CharacterAdded:Wait()

local humanoid = Character:WaitForChild("Humanoid")

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:connect(function(keyCode)
	local HRP = Character:FindFirstChild("HumanoidRootPart")

	if keyCode.keyCode == Enum.KeyCode.D then
		while keyCode.keyCode == Enum.KeyCode.D do
		Character:MoveTo(HRP.Position + Vector3.new(0,0,1))

	end

	end
end)

Note : the script idea is make player move right if he hold D (don’t ask me why)

Just write a bool variable to use as the debounce:

local Debounce = false
UserInputService.InputBegan:Connect(function(...))
    if not Debouce then
       Debounce = true
       -- Your code
       -- Cooldown (You can use spawn() or coroutine.wrap
       -- if you don't want to yield the thread)
    end
end)

Also read about ContextActionService | Roblox Creator Documentation, it’s useful when using UserInputService.

still don’t work but let me try something

Try searching “Debounce, when and why Roblox”.

I saw it but I didn’t understand because my English is very basic