Keybind printing output 5 times

Hello I am creating a ability system which does something after a key is pressed however it prints the output 5 times and fires the event five times.

The local script is inside the character model disabled then enables once spawning as the character and this is the only place where it is.

Here is the Local script:

> --Basic Witch Abilities
> 
> --Telekinetic Push
> task.spawn(function()
> 	local UIS = game:GetService("UserInputService")
> 	local Cooldown = 20
> 	local Debounce = false
> 	local Player = game.Players.LocalPlayer
> 	local Character = Player.Character
> 	local Mouse = Player:GetMouse()
> 	
> 	UIS.InputBegan:Connect(function(key, IsTyping)
> 		if key.KeyCode == Enum.KeyCode.C then
> 			if not IsTyping then
> 				if Mouse.Target.Parent:FindFirstChildWhichIsA("Humanoid") then
> 					if (Mouse.Target.Parent.HumanoidRootPart.Position - Character.HumanoidRootPart.Position).Magnitude < 10 then
> 						if Debounce == false then
> 							Debounce = true
> 							print(Mouse.Target.Parent)
> 							game.ReplicatedStorage.Remotes.Abilities:FireServer("Basic Telekinetic Push", Mouse.Target.Parent)
> 							wait(Cooldown)
> 							Debounce = false
> 						end
> 					else
> 						if Debounce == true then
> 							print(Cooldown)
> 						end
> 					end
> 				else
> 					if (Mouse.Target.Parent.HumanoidRootPart.Position - Character.HumanoidRootPart.Position).Magnitude > 10 then
> 						print("To far from Target")
> 					end
> 				end
> 			end
> 		end
> 	end)
> end)

This is the output:

Define the debounce outside the scope, your code is actually debouncing inside its own scope which doesn’t change anything. Think about if like a function or scope, how does anything else know that debounce? Move the Debounce to be a global variable and then change your code.

I removed the debounce completely aswell as the magnitude and it still printed 3 times

You need the debounce as UIS can fire many times per second during 1 key stroke. But you have to define the debounce outside and alter it from inside the if statement.

I don’t understand at all where would I define it and how would I alter it.