Crouch script not working

I fixed this problem by doing repeat wait() until Player.Character

I know this isn’t optimal but Player.CharacterAdded:Wait() yielded the script for some reason.

It still isn’t working though, when I press C, it doesn’t print anything but it goes through the UIS.InputBegan and UIS.InputEnded

-- This is the pc input handler.
wait(1.25);
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")

local Player = Players.LocalPlayer

repeat wait() until Player.Character

local Character = Player.Character
local CrouchKey = Enum.KeyCode.C
local Deb = false
-- Checks if Humanoid is Alive.
local function CheckAlive()
	local Hum = Character:FindFirstChild("Humanoid")
	local Head = Character:FindFirstChild("Head")
	local HumanRoot = Character:FindFirstChild("HumanoidRootPart")
	if Hum and Hum.Health > 0 and Head and HumanRoot then
		return true
	else
		return false
	end
end

-- Checks if head is in the way
local function CheckHead()
	if not CheckAlive() then return end

	local rayOrigin = script.Parent.Head.Position
	local rayDirection = Vector3.new(0, 2, 0)

	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {script.Parent}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

	if raycastResult then
		local hitPart = raycastResult.Instance
		if hitPart.Transparency == 0 then
			return false
		else
			return true
		end
	else
		return true
	end
end

-- Input begans, crouch idle
UIS.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end

	if input == CrouchKey and CheckAlive() == true then
		if not Deb then
			Deb = true
			local CrouchIdle = Character:WaitForChild("Humanoid").Animator:LoadAnimation(script.CrouchIdle)
			local Animate = Character:WaitForChild("Animate")
			CrouchIdle:Play()
			Animate.walk.WalkAnim.AnimationId = script.CrouchWalk.AnimationId
			game:GetService("TweenService"):Create(script.Parent:FindFirstChild("Humanoid"), TweenInfo.new(0.2), {HipHeight = 0.3}):Play()
		end
	end
end)
-- Input ends
UIS.InputEnded:Connect(function(input,gameProcessed)
	if gameProcessed then return end
	if input == CrouchKey and CheckAlive() == true then
		print("C Input end")
		if CheckHead() then
			Deb = false
			local Animate = Character:WaitForChild("Animate")
			local CrouchIdle = Character:WaitForChild("Humanoid").Animator:LoadAnimation(script.CrouchIdle)
			CrouchIdle:Stop()
			Animate.walk.WalkAnim.AnimationId = "rbxassetid://10898889275"
			game:GetService("TweenService"):Create(script.Parent:FindFirstChild("Humanoid"), TweenInfo.new(0.2), {HipHeight = 2}):Play()
		end
	end
end)

Edit: I fixed it by adding input.Keycode, oopsies the original problem was the character though since it was yielding the script.