I have had many problems that have required me to change my script a lot, so I decided to rewrite the entire remoteevent function according to the help I have received from the people on this website. I noticed that I now have ANOTHER issue, which I will explain now.

I have a LocalScript inside the player(s), which records if a player presses, and releases a certain key, which in this case, is Z. Pressing the key fires the GomuPistolEvent and KeyHeld = true, releasing the key fires the GomuPistolEvent and KeyHeld = false. My problem now is, that the first time the player presses Z, the lines 51 to 57 in the ServerScript aren't being initiated. everything runs smooth until those lines of code. The player's animation is not stopped, and it does not print "pistolcharge". this only happens the player presses Z for the first time. I have tested this in Play Solo, and in a Client/Server Simulation. Is there anyone to fix, or change this?

LocalScript:

--//Services
local UserInputService = game:GetService('UserInputService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ServerStorage = game:GetService('ServerStorage')
local ServerScriptService = game:GetService('ServerScriptService')
local Players = game:GetService('Players')

--//Variables
local GomuRemotes = ReplicatedStorage.Remotes.DevilFruits:WaitForChild('GomuGomu')
local GomuPistolEvent = GomuRemotes.GomuPistol:WaitForChild('GomuPistolEvent')
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local MousePosition = Mouse.Hit.p
local GomuPistolCooldown = 5
local KeyHeld = true
Debounce = false

--//Coding
function onKeyPress(input, gameEvent)
	if not Debounce and not gameEvent then
		Debounce = true
		if input.KeyCode == Enum.KeyCode.Z then
			KeyHeld = true
			GomuPistolEvent:FireServer(KeyHeld, MousePosition)
			print('Z')
		end
		if input.KeyCode == Enum.KeyCode.X then
		end
		if input.KeyCode == Enum.KeyCode.C then
		end
		if input.KeyCode == Enum.KeyCode.V then
		end
		if input.KeyCode == Enum.KeyCode.B then
		end
		Debounce = false
	end
end
function onKeyRelease(input)
	if not Debounce then
		Debounce = true
		if input.KeyCode == Enum.KeyCode.Z then
			KeyHeld = false
			GomuPistolEvent:FireServer(KeyHeld, MousePosition)
			print('ZRelease')
			wait(GomuPistolCooldown)
		end
		if input.KeyCode == Enum.KeyCode.X then
		end
		if input.KeyCode == Enum.KeyCode.C then
		end
		if input.KeyCode == Enum.KeyCode.V then
		end
		if input.KeyCode == Enum.KeyCode.B then
		end
	Debounce = false
	end
end

UserInputService.InputBegan:Connect(onKeyPress)
UserInputService.InputEnded:Connect(onKeyRelease)

ServerScript:

--//Services
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ServerStorage = game:GetService('ServerStorage')
local ServerScriptService = game:GetService('ServerScriptService')
local Players = game:GetService('Players')
local GomuRemotes = ReplicatedStorage.Remotes.DevilFruits:WaitForChild('GomuGomu')

--//Variables
local GomuPistolEvent = GomuRemotes.GomuPistol:WaitForChild('GomuPistolEvent')
local DamageModule = require(ServerStorage.Server.DamageService)
local GomuAssets = ServerStorage.Assets.DevilFruits:WaitForChild('GomuGomu')

--//Animations
local GomuPistolAnim = Instance.new('Animation')
GomuPistolAnim.AnimationId = 'rbxassetid://2188557970'
GomuPistolAnimTrack = nil

--//Sounds
local GomuStretchSndFX = GomuAssets.SoundFX:WaitForChild('GomuStretch'):Clone()

--//Coding
function Weld(Part0, Part1, C0, C1)
	local nWeld = Instance.new("Weld")
		nWeld.Part0 = Part0
		nWeld.Part1 = Part1
		nWeld.C0 = C0 or CFrame.new(0, 0, 0)
		nWeld.C1 = C1 or CFrame.new(0, 0, 0)
		nWeld.Parent = Part0
	return nWeld 	
end

function GomuGomuPistol(PlayerWhoSent, KeyHeld, MousePosition)
	local Character = PlayerWhoSent.Character
	local Humanoid = Character:FindFirstChildOfClass('Humanoid')
	local RightArm = Character:WaitForChild('RightLowerArm')
	local RightHand = Character:WaitForChild('RightHand')
	local LeftArm = Character:WaitForChild('LeftLowerArm')
	local LeftHand = Character:WaitForChild('LeftHand')
	local Damaging = false
	local Attacking = false
	local Damage = 25
	local Range = 25
	local BodyGyro = Instance.new('BodyGyro')
	local BodyPosition = Instance.new('BodyPosition')
	local ArmStretch = Instance.new('Part')
	
	if KeyHeld then
		print('keyheld')
		GomuPistolAnimTrack = Humanoid:LoadAnimation(GomuPistolAnim)
		GomuPistolAnimTrack:Play()
		GomuPistolAnimTrack.KeyframeReached:Connect(function(Keyframe)
			if Keyframe == 'Charge' and KeyHeld then
				GomuPistolAnimTrack:AdjustSpeed(0)
				print('pistolcharge')
				Attacking = true
			end
		end)
	elseif not KeyHeld then
		print('notkeyheld')
		GomuPistolAnimTrack:AdjustSpeed(1)
		Humanoid.WalkSpeed = 0
		print('pistol')
		wait(5)
	end
	Humanoid.WalkSpeed = 16

	RightArm.Touched:Connect(function(hitPart)
		if Attacking and hitPart.Parent:FindFirstChild('Humanoid') and Damaging then
			Damaging = false
			local HumanoidToDamage = hitPart.Parent:FindFirstChild('Humanoid')
			DamageModule.Combat(HumanoidToDamage, Damage)
		end
	end)
	LeftArm.Touched:Connect(function(hitPart)
		if Attacking and hitPart.Parent:FindFirstChild('Humanoid') and Damaging then
			Damaging = false
			local HumanoidToDamage = hitPart.Parent:FindFirstChild('Humanoid')
			DamageModule.Combat(HumanoidToDamage, Damage)
		end
	end)
end

GomuPistolEvent.OnServerEvent:Connect(GomuGomuPistol)