Issues with raycast

Trying to make anti fly and getting errors

Error: Unable to cast double to Vector3

local cast = workspace:Raycast(character.PrimaryPart.Position, -getRayHeight(character), playerRaycastParams)

			local isOnGround = cast and cast.Instance.CanCollide
			if isOnGround then
				playerState.lastOnTheGround = tick()
			end
			local distance = ((playerState.lastPosition - character.PrimaryPart.Position) * Vector3.new(0, 1, 0)).Magnitude

			if distance >= 0 and tick() - playerState.lastOnTheGround > 5 then
				print("The player triggered the anti-fly check!")
			end
local distance = (playerState.lastPosition - character.PrimaryPart.Position).Magnitude

Make sure -getRayHeight(character) is returning a valid Vector3 value of the Vector3 class as well.

It seems to print -3.999999523162842

The issue is right here

What is “getRayHeight”? According to your error description, it is returning a type double (a number) instead of type Vector3.

local function getRayHeight(character)
	local R15 = character.Humanoid.RigType == Enum.HumanoidRigType.R15
	return R15 and character.Humanoid.HipHeight + character.Humanoid.RootPart.Size.Y/2 + 1 or 3.5
end

change -getRayHeight(character) to Vector3.new(0,-getRayHeight(character),0)